Skip to content

Instantly share code, notes, and snippets.

@trungtran
Created December 11, 2012 20:44
Show Gist options
  • Save trungtran/4261975 to your computer and use it in GitHub Desktop.
Save trungtran/4261975 to your computer and use it in GitHub Desktop.
import os
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
msg = MIMEMultipart()
msg['Subject'] = "A subject"
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
# Attach Message
msg.attach(MIMEText("Test body"))
# Send the message
sendmail = os.popen('sendmail [email protected]', 'w')
sendmail.write(msg.as_string())
# Print sucess/failure
if sendmail.close() is not None:
print 'Error sending mail';
else:
print 'Sent mail successfully'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment