Last active
December 28, 2015 10:19
-
-
Save khibma/7485344 to your computer and use it in GitHub Desktop.
Send email
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
def sendEmail(content, images): | |
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from email.mime.image import MIMEImage | |
FROM = '[email protected]' | |
TO = '[email protected]' | |
msg = MIMEMultipart() | |
msg['From'] = FROM | |
msg['To'] = TO | |
msg['Subject'] = "EMAIL SUBJECT LINE" | |
#MIMEText('<html><body><b>hello</b><br><img src="cid:graph"><br></body></html>', 'html') | |
msgText = MIMEText(content, 'html') | |
msg.attach(msgText) | |
if images is not None: | |
for k, v in images.iteritems(): | |
fp = open(v, 'rb') | |
img = MIMEImage(fp.read()) | |
fp.close() | |
#img.add_header('Content-ID', '<graph>') | |
img.add_header('Content-ID', '<{}>'.format(str(k))) | |
msg.attach(img) | |
# Send the mail | |
server = smtplib.SMTP("EMAILSERVER.COM") | |
server.sendmail(FROM, TO, msg.as_string()) | |
server.quit() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment