Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Sending an Email with Python3 via smtplib

From John's Wiki

It possible to use the module smtplib to send an Email with python3.

#!/usr/bin/env python3

import smtplib 
from email.message import EmailMessage

to_addr = 'to@example.com'
from_addr = 'from@example.com'
mail_server = 'mail.example.com'
passwd = 'YOUR_MAILBOX_PASSWORD'

message = EmailMessage()
message["To"]      = to_addr
message["From"]    = from_addr
message["Subject"] = 'Sent with Python & Smtplib'
message.set_payload('This is a test message!')

s = smtplib.SMTP_SSL(mail_server, 465)
s.login(to_addr, passwd)
s.sendmail(to_addr, from_addr, message.as_string())
s.quit()