Receive and send emails in python

Here is a very simple example:

import smtplib

server="mail.server.com"
user=""
password = ''

recipients = ['[email protected]', '[email protected]']
sender="[email protected]"
message="Hello World"

session = smtplib.SMTP(server)
# if your SMTP server doesn't need authentications,
# you don't need the following line:
session.login(user, password)
session.sendmail(sender, recipients, message)

For more options, error handling, etc, look at the smtplib module documentation.

Leave a Comment