Python: Send Email via Office 365

  • by

Please refer to the following Python Script to send Email via Office 365 with TLS 

Encrypted your password

import base64
print base64.b64encode("XXXXXX") #Your Password here
print base64.b64decode("UEBzc3cwcmR3dms0ODk3")

This is the actual script that will send email via Office 365 to my Gmail

import smtplib
import base64

sendto = ''
user= ''
password = base64.b64decode("UEBzc3cwcmR3dms0ODk3")
smtpsrv = ""
smtpserver = smtplib.SMTP(smtpsrv,587)

smtpserver.login(user, password)
header = 'To:' + sendto + 'n' + 'From: ' + user + 'n' + 'Subject:testing n'
print header
msgbody = header + 'n This is a test Email send using Python nn'
smtpserver.sendmail(user, sendto, msgbody)
print 'done!'