-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendMail.py
72 lines (58 loc) · 2.54 KB
/
sendMail.py
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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
#configurações do servidor SMTP
server_smtp = "smtp.gmail.com"
port = 587
sender_email = "[email protected]"
password = "insira_sua_senha_aqui" #gerar senhas de app na sua conta google
#configurações do email
receive_email = "[email protected]" #pode ser qualquer email
subject = "E-mail automático em python" # adicione o assunto do email
body = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Teste</title>
</head>
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif; background-color: #f2f2f2;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #f2f2f2;">
<tr>
<td align="center">
<table border="0" cellpadding="0" cellspacing="0" width="600" style="background-color: #ffffff;">
<tr>
<td align="center" style="padding: 40px 0;">
<img src="https://img.freepik.com/fotos-gratis/paisagem-de-nevoeiro-matinal-e-montanhas-com-baloes-de-ar-quente-ao-nascer-do-sol_335224-794.jpg" alt="Paisagem" width="400" style="display: block; margin: 0 auto;">
<p style="margin-top: 20px; text-align: center;">Olá,</p>
<p style="text-align: center;">Este é um e-mail de teste com uma imagem anexada.</p>
<p style="text-align: center;">Agradecemos por ter recebido este e-mail de teste.</p>
<p style="text-align: center;">Este e-mail foi enviado apenas para fins de demonstração e teste.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
"""
#Criando o e-mail
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receive_email
message["Subject"] = subject
message.attach(MIMEText(body, "html"))
#conectando o servidor SMTP
try:
server = smtplib.SMTP(server_smtp, port)
server.starttls()
server.login(sender_email,password)
server.sendmail(sender_email, receive_email, message.as_string())
print("Email enviado com sucesso")
except Exception as e:
print(f'Houve algum erro: {e}')
finally:
server.quit()