Created
July 31, 2019 12:07
-
-
Save scionoftech/39f3807ca34537f2b4b62152c25fe32c to your computer and use it in GitHub Desktop.
A simple python script to send email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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