Last active
March 28, 2020 16:38
-
-
Save btarg/dd0523da3c1469c4e4e2643c05e87db8 to your computer and use it in GitHub Desktop.
Send Emails in Python 3
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
# Send emails in Python, converted for Python 3.6 by iCrazyBlaze | |
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
# Your email details | |
fromaddr = "your email" | |
PASSWORD = "your password" | |
# Email message | |
SUBJECT = "Test message" | |
body = "This is a test" | |
toaddr = "address of who you're sending it to" | |
try: | |
msg = MIMEMultipart() | |
msg['From'] = fromaddr | |
msg['To'] = toaddr | |
msg['Subject'] = SUBJECT | |
msg.attach(MIMEText(body, 'plain')) | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.starttls() | |
server.login(fromaddr, PASSWORD) | |
text = msg.as_string() | |
server.sendmail(fromaddr, toaddr, text) | |
server.quit() | |
print("Email sent to '" + toaddr + "' successfully!") | |
except: | |
print("An error occured!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not Working