forked from dunossauro/Py.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_email_email.py
43 lines (33 loc) · 1.25 KB
/
send_email_email.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
"""
Exemplo de um temporazidor que evenia e-mail em um tempo pré definido
Nesse caso ele enviara um e-mail a cada 10 segundos para todos da lista
Com a hora/data atual.
"""
import smtplib
from time import sleep
from time import gmtime, strftime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail_dict = {'subject': 'ASSUNTO',
'from': 'teste@gmail.com',
'msg': 'Teste'}
def run_task(mails: list, mail_dict: dict, time_sec: int = 10) -> None:
while True:
for mail in mails:
msg = MIMEMultipart('alternative')
msg['Subject'] = mail_dict['subject']
msg['From'] = mail_dict['from']
msg['To'] = mail
me = mail_dict['from']
you = mail
text = 'Hora atual\n\n{}'.format(strftime("%Y-%m-%d %H:%M:%S",
gmtime()))
msg = MIMEText(text, 'plain')
mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.ehlo()
mail.starttls()
mail.login(mail_dict['from'], "senha")
mail.sendmail(me, you, msg.as_string())
mail.quit()
sleep(10)
run_task(['teste@gmail.com', 'teste@gmail.com'], mail_dict)