To send an email in Python, follow these steps along with the code:

Example

                                        

import smtplib

sender = '[email protected]'
receivers = ['[email protected]']

message = """From: From Person <[email protected]>
To: To Person <[email protected]>
Subject: SMTP email test in Python

This is a test email message in Python.
"""

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent the email"
except SMTPException:
   print "Error display: Python is unable to send an email"

Suggest An Answer

No suggestions Available!