habulaj commited on
Commit
5467611
·
verified ·
1 Parent(s): d6e7efb

Update routes/emails.py

Browse files
Files changed (1) hide show
  1. routes/emails.py +7 -7
routes/emails.py CHANGED
@@ -1,5 +1,4 @@
1
  import base64
2
- import json
3
  import aiohttp
4
  from fastapi import APIRouter, HTTPException, Query
5
  from google.auth.transport.requests import Request
@@ -9,12 +8,11 @@ from email.utils import formataddr
9
 
10
  router = APIRouter()
11
 
12
- # Google OAuth2 Config
13
  CLIENT_ID = "1033810476410-cd4t2ojekl2qmek6o0na1uj9gcdonu2d.apps.googleusercontent.com"
14
  CLIENT_SECRET = "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"
15
- REFRESH_TOKEN = "1//04-7T3Id2qJJ-CgYIARAAGAQSNwF-L9Ir__mLsismQuTKTggDk2YF3d_NHx1gKcymnnlYh_x_x76SDREVWap0mzSgeqmWCD23exg"
16
  EMAIL_ADDRESS = "[email protected]"
17
- SENDER_NAME = "Streamify"
18
 
19
  SCOPES = ['https://www.googleapis.com/auth/gmail.send']
20
 
@@ -33,11 +31,13 @@ def get_access_token():
33
  async def send_email_gmail(to_email: str, subject: str, body_html: str):
34
  access_token = get_access_token()
35
 
36
- # Codifica o título corretamente com UTF-8 (RFC 2047)
37
  encoded_subject = str(Header(subject, 'utf-8'))
38
 
39
- # Formata o e-mail com todos os headers corretamente
40
- message = f"""From: {formataddr((SENDER_NAME, EMAIL_ADDRESS))}
 
 
41
  To: {to_email}
42
  Subject: {encoded_subject}
43
  MIME-Version: 1.0
 
1
  import base64
 
2
  import aiohttp
3
  from fastapi import APIRouter, HTTPException, Query
4
  from google.auth.transport.requests import Request
 
8
 
9
  router = APIRouter()
10
 
 
11
  CLIENT_ID = "1033810476410-cd4t2ojekl2qmek6o0na1uj9gcdonu2d.apps.googleusercontent.com"
12
  CLIENT_SECRET = "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"
13
+ REFRESH_TOKEN = "1//048eSNFimtH-5CgYIARAAGAQSNwF-L9IrnsvcPX_TMwXfyaTTtfgeMlANP3uqoKw2IK7Ww0eB50EXYGMEtwrTDEfT157PgoC1J9s"
14
  EMAIL_ADDRESS = "[email protected]"
15
+ SENDER_NAME = "Ameddes"
16
 
17
  SCOPES = ['https://www.googleapis.com/auth/gmail.send']
18
 
 
31
  async def send_email_gmail(to_email: str, subject: str, body_html: str):
32
  access_token = get_access_token()
33
 
34
+ # Codifica o assunto (subject) corretamente com UTF-8, base64 (RFC 2047)
35
  encoded_subject = str(Header(subject, 'utf-8'))
36
 
37
+ # Monta o cabeçalho com o nome do remetente e e-mail corretamente formatados
38
+ from_header = formataddr((SENDER_NAME, EMAIL_ADDRESS))
39
+
40
+ message = f"""From: {from_header}
41
  To: {to_email}
42
  Subject: {encoded_subject}
43
  MIME-Version: 1.0