from email MIMEMultipart import MIMEMultipart from email MIMEText impo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
strFrom = 'qwe@example.com'
COMMASPACE = ', '
strTo = ['mails@list']
# Create the root message and fill in the from, to, and subject headers
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'Automated tests results'
msgRoot['From'] = strFrom
msgRoot['To'] = COMMASPACE.join(strTo)
msgRoot.preamble = 'This is a multi-part message in MIME format.'
# Encapsulate the plain and HTML versions of the message body in an
# 'alternative' part, so message agents can decide which they want to display.
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgText = MIMEText('I'm not html text')
msgAlternative.attach(msgText)
report = '<html>I am html</html>
msgText = MIMEText(report, 'html')
msgAlternative.attach(msgText)
import smtplib
smtp = smtplib.SMTP()
smtp.connect('mail.example.com')
#smtp.login('exampleuser', 'examplepass')
smtp.sendmail(strFrom, strTo, msgRoot.as_string())
smtp.quit()