MCPcopy Create free account
hub / github.com/ActiveState/code / mail

Function mail

recipes/Python/576547_Code_solve_Smoluchowsky/recipe-576547.py:15–38  ·  view source on GitHub ↗
(to, subject, text, attach)

Source from the content-addressed store, hash-verified

13
14
15def mail(to, subject, text, attach):
16 msg = MIMEMultipart()
17
18 msg['From'] = gmail_user
19 msg['To'] = to
20 msg['Subject'] = subject
21
22 msg.attach(MIMEText(text))
23
24 part = MIMEBase('application', 'octet-stream')
25 part.set_payload(open(attach, 'rb').read())
26 Encoders.encode_base64(part)
27 part.add_header('Content-Disposition',
28 'attachment; filename="%s"' % os.path.basename(attach))
29 msg.attach(part)
30
31 mailServer = smtplib.SMTP("smtp.gmail.com", 587)
32 mailServer.ehlo()
33 mailServer.starttls()
34 mailServer.ehlo()
35 mailServer.login(gmail_user, gmail_pwd)
36 mailServer.sendmail(gmail_user, to, msg.as_string())
37 # Should be mailServer.quit(), but that crashes...
38 mailServer.close()
39
40
41def Brow_ker_cont_optim(Vlist):

Callers 1

recipe-576547.pyFile · 0.70

Calls 6

add_headerMethod · 0.80
loginMethod · 0.80
openFunction · 0.50
attachMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected