Email

Email using smtplib

Simple Version

import smtplib

recipient='[email protected]'
cc=''
sender='[email protected]'
server='smtp.domain.com'
subject='Backup Report'
message='This is test message'

header='From: %s\n' % sender
header+='To: %s\n' % recipient
header+='CC: %s\n' % cc
header+='Subject: %s\n\n' % subject
message = header + message

connection = smtplib.SMTP(server)
result = connection.sendmail(sender,recipient,message)
connection.quit()
print(result)

With Attachment

With Attachment and Authentication

Another Version

Example to send Backup Report

Reference

  • https://realpython.com/python-send-email/

  • http://rosettacode.org/wiki/Send_email#Python

  • http://www.blog.pythonlibrary.org/2013/06/26/python-102-how-to-send-an-email-using-smtplib-email/

Last updated