Created
January 1, 2014 10:24
-
-
Save aymanfarhat/8206766 to your computer and use it in GitHub Desktop.
Python snippet for sending email using unix sendmail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from subprocess import Popen, PIPE | |
html = MIMEText("<html><head><title>Test Email</title></head><body>Some HTML</body>", "html") | |
msg = MIMEMultipart("alternative") | |
msg["From"] = "[email protected]" | |
msg["To"] = "[email protected]" | |
msg["Subject"] = "Python sendmail test" | |
msg.attach(html) | |
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE) | |
p.communicate(msg.as_string()) |
in Python 3 change last line to:
p.communicate(msg.as_string().encode())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sendmail: fatal: oracle(501): No recipient addresses found in message header