blob: f69ef40ff04c9343c43237f4ce3fd12f179b5c2d [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001# Import smtplib for the actual sending function
2import smtplib
3
4# Import the email modules we'll need
R David Murray29d1bc02016-09-07 21:15:59 -04005from email.message import EmailMessage
Georg Brandl116aa622007-08-15 14:28:22 +00006
R David Murray29d1bc02016-09-07 21:15:59 -04007# Open the plain text file whose name is in textfile for reading.
Berker Peksagf9e3cf12015-02-25 18:14:09 +02008with open(textfile) as fp:
9 # Create a text/plain message
R David Murray29d1bc02016-09-07 21:15:59 -040010 msg = EmailMessage()
11 msg.set_content(fp.read())
Georg Brandl116aa622007-08-15 14:28:22 +000012
13# me == the sender's email address
14# you == the recipient's email address
15msg['Subject'] = 'The contents of %s' % textfile
16msg['From'] = me
17msg['To'] = you
18
R. David Murray7dff9e02010-11-08 17:15:13 +000019# Send the message via our own SMTP server.
R David Murraybb754b52011-04-30 17:26:32 -040020s = smtplib.SMTP('localhost')
R David Murray74612982011-04-30 17:19:53 -040021s.send_message(msg)
Jeroen Ruigrok van der Werven939c1782009-04-26 20:25:45 +000022s.quit()