Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | # Import smtplib for the actual sending function |
| 2 | import smtplib |
| 3 | |
| 4 | # Import the email modules we'll need |
| 5 | from email.mime.text import MIMEText |
| 6 | |
| 7 | # Open a plain text file for reading. For this example, assume that |
| 8 | # the text file contains only ASCII characters. |
Berker Peksag | f9e3cf1 | 2015-02-25 18:14:09 +0200 | [diff] [blame] | 9 | with open(textfile) as fp: |
| 10 | # Create a text/plain message |
| 11 | msg = MIMEText(fp.read()) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 12 | |
| 13 | # me == the sender's email address |
| 14 | # you == the recipient's email address |
| 15 | msg['Subject'] = 'The contents of %s' % textfile |
| 16 | msg['From'] = me |
| 17 | msg['To'] = you |
| 18 | |
R. David Murray | 7dff9e0 | 2010-11-08 17:15:13 +0000 | [diff] [blame] | 19 | # Send the message via our own SMTP server. |
R David Murray | bb754b5 | 2011-04-30 17:26:32 -0400 | [diff] [blame] | 20 | s = smtplib.SMTP('localhost') |
R David Murray | 7461298 | 2011-04-30 17:19:53 -0400 | [diff] [blame] | 21 | s.send_message(msg) |
Jeroen Ruigrok van der Werven | 939c178 | 2009-04-26 20:25:45 +0000 | [diff] [blame] | 22 | s.quit() |