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

Update routes/emails.py

Browse files
Files changed (1) hide show
  1. routes/emails.py +10 -2
routes/emails.py CHANGED
@@ -4,6 +4,8 @@ import aiohttp
4
  from fastapi import APIRouter, HTTPException, Query
5
  from google.auth.transport.requests import Request
6
  from google.oauth2.credentials import Credentials
 
 
7
 
8
  router = APIRouter()
9
 
@@ -12,6 +14,7 @@ CLIENT_ID = "1033810476410-cd4t2ojekl2qmek6o0na1uj9gcdonu2d.apps.googleuserconte
12
  CLIENT_SECRET = "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"
13
  REFRESH_TOKEN = "1//04-7T3Id2qJJ-CgYIARAAGAQSNwF-L9Ir__mLsismQuTKTggDk2YF3d_NHx1gKcymnnlYh_x_x76SDREVWap0mzSgeqmWCD23exg"
14
  EMAIL_ADDRESS = "[email protected]"
 
15
 
16
  SCOPES = ['https://www.googleapis.com/auth/gmail.send']
17
 
@@ -30,9 +33,14 @@ def get_access_token():
30
  async def send_email_gmail(to_email: str, subject: str, body_html: str):
31
  access_token = get_access_token()
32
 
33
- message = f"""From: Streamify <{EMAIL_ADDRESS}>
 
 
 
 
34
  To: {to_email}
35
- Subject: {subject}
 
36
  Content-Type: text/html; charset="UTF-8"
37
 
38
  {body_html}
 
4
  from fastapi import APIRouter, HTTPException, Query
5
  from google.auth.transport.requests import Request
6
  from google.oauth2.credentials import Credentials
7
+ from email.header import Header
8
+ from email.utils import formataddr
9
 
10
  router = APIRouter()
11
 
 
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
  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
44
  Content-Type: text/html; charset="UTF-8"
45
 
46
  {body_html}