Skip to content

Instantly share code, notes, and snippets.

@scionoftech
Created July 31, 2019 12:07
Show Gist options
  • Save scionoftech/39f3807ca34537f2b4b62152c25fe32c to your computer and use it in GitHub Desktop.
Save scionoftech/39f3807ca34537f2b4b62152c25fe32c to your computer and use it in GitHub Desktop.
A simple python script to send email
import smtplib
"""
SMTP Server Information
1. Gmail.com: smtp.gmail.com:587
2. Outlook.com: smtp-mail.outlook.com:587
3. Office 365: outlook.office365.com
Please verify your SMTP settings info.
"""
FROM = "YOUR EMAIL ID"
PWD = "PASSWROD"
recipient = ["RECIPIENT EMAIL ID"]
TO = recipient if isinstance(recipient, list) else [recipient]
SUBJECT = "Test Message"
TEXT = "Hello"
# Function that send email.
def send_mail(username, password, from_addr, to_addrs, msg):
server = smtplib.SMTP('smtp-mail.outlook.com', '587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(from_addr, to_addrs, message)
server.quit()
# prepaire message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send Email
send_mail(FROM,PWD,FROM,TO,message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment