-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_utils.py
More file actions
208 lines (169 loc) · 8.76 KB
/
email_utils.py
File metadata and controls
208 lines (169 loc) · 8.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import os
from fastapi_mail import FastMail, MessageSchema, ConnectionConfig, MessageType
from pydantic import EmailStr
from pathlib import Path
conf = ConnectionConfig(
MAIL_USERNAME="adatech04@gmail.com", # Coloque seu e-mail aqui
MAIL_PASSWORD="hevhceqfzcygerij", # Coloque sua senha de aplicativo aqui
MAIL_FROM="adatech04@gmail.com", # Quem está enviando
MAIL_PORT=587,
MAIL_SERVER="smtp.gmail.com",
MAIL_STARTTLS=True,
MAIL_SSL_TLS=False,
USE_CREDENTIALS=True,
VALIDATE_CERTS=True
)
# 2. FUNÇÃO DE ENVIO (COM O LAYOUT BONITO)
async def send_welcome_email(email_to: EmailStr, name: str):
# Definindo cores baseadas no conceito 'Tech'
primary_color = "#2B4C7E"
bg_color = "#F4F4F7"
# Garante que o caminho para a pasta static esteja correto
# Ajuste "static" se sua pasta tiver outro nome ou caminho
base_dir = Path(__file__).resolve().parent
logo_path = base_dir / "static" / "rodape.jpeg" # Certifique-se que o arquivo NÃO tem acento
html = f"""
<!DOCTYPE html>
<html>
<body style="margin: 0; padding: 0; background-color: {bg_color}; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;">
<div style="width: 100%; background-color: {bg_color}; padding: 40px 0;">
<div style="max-width: 600px; margin: 0 auto; background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
<div style="padding: 40px 40px 20px 40px;">
<h2 style="color: {primary_color}; margin-top: 0; font-size: 24px;">Olá, {name}!</h2>
<p style="color: #555; font-size: 16px; line-height: 1.6;">
Seja muito bem-vindo(a) à <strong>AdaTech</strong>. É um prazer ter você conosco.
</p>
<p style="color: #555; font-size: 16px; line-height: 1.6;">
Seu cadastro foi concluído com sucesso. A partir de agora, você tem em mãos uma solução
desenvolvida para elevar a eficiência e a segurança do seu registro aduaneiro.
</p>
<div style="background-color: #F8F9FA; border-left: 4px solid {primary_color}; padding: 20px; margin: 25px 0; border-radius: 4px;">
<p style="margin: 0; color: #333; font-size: 15px; line-height: 1.6;">
<strong>O que a AdaTech faz por você:</strong><br><br>
Nossa plataforma automatiza a criação da instrução de registro, integrando inteligentemente:
</p>
<ul style="margin: 10px 0 0 0; padding-left: 20px; color: #555;">
<li>Part-Number e Classificação Fiscal</li>
<li>Dados do Fabricante</li>
<li>Origem da mercadoria</li>
</ul>
</div>
<p style="color: #555; font-size: 16px; line-height: 1.6;">
Nosso objetivo é gerar descrições completas e compatíveis com as exigências legais.
</p>
<p style="margin-top: 30px; color: #333; font-weight: bold;">
Atenciosamente,<br>
<span style="color: {primary_color};">Equipe Adalove</span>
</p>
</div>
<div style="width: 100%; margin-top: 10px;">
<img src="cid:rodape" alt="AdaTech Footer" style="width: 100%; display: block; border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;" />
</div>
</div>
<div style="text-align: center; padding-top: 20px; color: #999; font-size: 12px;">
© 2025 Adalove. Todos os direitos reservados.
</div>
</div>
</body>
</html>
"""
message = MessageSchema(
subject="Bem-vindo(a) à AdaTech!",
recipients=[email_to],
body=html,
subtype=MessageType.html,
attachments=[
{
"file": str(logo_path),
"headers": {
"Content-ID": "<rodape>",
"Content-Disposition": "inline"
},
"mime_type": "image", # <--- (Boa prática)
"mime_subtype": "jpeg"
}
]
)
fm = FastMail(conf)
try:
await fm.send_message(message)
except Exception as e:
print(f"Erro ao tentar enviar o email: {e}")
# É uma boa ideia logar esse erro em um arquivo
async def send_recovery_email(email_to: EmailStr, code: str):
"""
Envia um email estilizado com o código de recuperação.
"""
# Configurações de Estilo (Mantendo a identidade da AdaTech)
primary_color = "#2B4C7E"
secondary_color = "#E8F0FE" # Um azul bem clarinho para fundo de destaque
bg_color = "#F4F4F7"
text_color = "#333333"
# Caminho da imagem (O mesmo da função de Welcome)
base_dir = Path(__file__).resolve().parent
logo_path = base_dir / "static" / "rodape.jpeg"
html = f"""
<!DOCTYPE html>
<html>
<body style="margin: 0; padding: 0; background-color: {bg_color}; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;">
<div style="width: 100%; background-color: {bg_color}; padding: 40px 0;">
<div style="max-width: 500px; margin: 0 auto; background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
<div style="background-color: {primary_color}; height: 8px; width: 100%;"></div>
<div style="padding: 40px 40px 30px 40px; text-align: center;">
<div style="font-size: 40px; margin-bottom: 10px;">🔒</div>
<h2 style="color: {primary_color}; margin-top: 0; margin-bottom: 10px; font-size: 24px;">
Recuperação de Senha
</h2>
<p style="color: #666; font-size: 16px; line-height: 1.5; margin-bottom: 25px;">
Recebemos uma solicitação para redefinir a senha da sua conta <strong>AdaTech</strong>.
</p>
<div style="background-color: {secondary_color}; border: 1px dashed {primary_color}; border-radius: 8px; padding: 20px; margin: 20px 0;">
<p style="margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: {primary_color}; font-weight: bold;">
Seu código de verificação
</p>
<p style="margin: 10px 0 0 0; font-size: 36px; letter-spacing: 8px; font-weight: bold; color: #333; font-family: 'Courier New', monospace;">
{code}
</p>
</div>
<p style="color: #888; font-size: 14px; margin-top: 25px;">
Este código é válido por <strong>15 minutos</strong>.
</p>
<hr style="border: none; border-top: 1px solid #eee; margin: 30px 0;">
<p style="color: #999; font-size: 12px; line-height: 1.4;">
Se você não solicitou essa alteração, por favor ignore este e-mail ou entre em contato com o suporte. Nenhuma alteração foi feita em sua conta.
</p>
</div>
<div style="width: 100%;">
<img src="cid:rodape" alt="AdaTech Footer" style="width: 100%; display: block;" />
</div>
</div>
<div style="text-align: center; padding-top: 20px; color: #999; font-size: 12px;">
© 2025 Adalove. Segurança em primeiro lugar.
</div>
</div>
</body>
</html>
"""
message = MessageSchema(
subject="AdaTech - Código de Recuperação",
recipients=[email_to],
body=html,
subtype=MessageType.html,
# IMPORTANTE: Adicionei os anexos aqui também para a imagem funcionar
attachments=[
{
"file": str(logo_path),
"headers": {
"Content-ID": "<rodape>",
"Content-Disposition": "inline"
},
"mime_type": "image",
"mime_subtype": "jpeg"
}
]
)
fm = FastMail(conf)
try:
await fm.send_message(message)
except Exception as e:
print(f"Erro ao enviar email de recuperação: {e}")