· 6 years ago · Aug 12, 2019, 09:02 AM
1import smtplib
2"""
3SMTP Server Information
41. Gmail.com: smtp.gmail.com:587
52. Outlook.com: smtp-mail.outlook.com:587
63. Office 365: outlook.office365.com
7Please verify your SMTP settings info.
8"""
9
10FROM = "YOUR EMAIL ID"
11PWD = "PASSWROD"
12recipient = ["RECIPIENT EMAIL ID"]
13TO = recipient if isinstance(recipient, list) else [recipient]
14SUBJECT = "Test Message"
15TEXT = "Hello"
16
17# Function that send email.
18def send_mail(username, password, from_addr, to_addrs, msg):
19 server = smtplib.SMTP('smtp-mail.outlook.com', '587')
20 server.ehlo()
21 server.starttls()
22 server.ehlo()
23 server.login(username, password)
24 server.sendmail(from_addr, to_addrs, message)
25 server.quit()
26
27# prepaire message
28message = """From: %s\nTo: %s\nSubject: %s\n\n%s
29 """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
30
31# Send Email
32send_mail(FROM,PWD,FROM,TO,message)