Update routes/emails.py
Browse files- 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//
|
16 |
EMAIL_ADDRESS = "[email protected]"
|
17 |
-
SENDER_NAME = "
|
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
|
37 |
encoded_subject = str(Header(subject, 'utf-8'))
|
38 |
|
39 |
-
#
|
40 |
-
|
|
|
|
|
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
|