Skip to content

Instantly share code, notes, and snippets.

@btarg
Last active March 28, 2020 16:38
Show Gist options
  • Save btarg/dd0523da3c1469c4e4e2643c05e87db8 to your computer and use it in GitHub Desktop.
Save btarg/dd0523da3c1469c4e4e2643c05e87db8 to your computer and use it in GitHub Desktop.
Send Emails in Python 3
# 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!")
@sahithyandev
Copy link

Not Working

@lefatoum
Copy link

not Working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment