i made a send mail program for python 2.7. You can view it here to compare the changes.

However in python 3 the code has been changed.

Below is the code for python 3

I tested it on python 3.4

 

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header

 
fromaddr=’YOUR EMAIL HERE’
toaddr=’ADDRESSEE EMAIL HERE’
thesub=’SUBJECT HERE’
thebody=’BODY HERE’
thepassword=’PASSWORD HERE’
domsmtp=’SMTP HERE’
smtpport= PORT HERE #needs integer not string

 
msg = MIMEMultipart(‘alt text here’)
msg.set_charset(‘utf8’)

 
msg[‘From’] = fromaddr
msg[‘To’] = toaddr
msg[‘Subject’] = Header(thesub,’utf8′)
_attach = MIMEText(thebody.encode(‘utf8′),’html’,’UTF-8′)
msg.attach(_attach)

 

 

server = smtplib.SMTP(domsmtp, smtpport)
server.starttls()
server.login(fromaddr, thepassword)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)

server.quit()

with support for fixes from stack overflow

Advertisements