Last active
April 1, 2018 14:33
-
-
Save youandhubris/0f54e218048a44b691042a2837962c24 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/python | |
# -*- coding: utf-8 -*- | |
import sys | |
import smtplib | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email import Encoders | |
# GMAIL | |
username = '[email protected]' | |
password = 'password' | |
# MESSAGE SETTINGS | |
SUBJECT = 'Subject String' | |
EMAIL_FROM = 'Email From String <[email protected]>' | |
MAIL_TO = ''.join(sys.argv[1]) | |
MAIL_TO_LIST = ['[email protected]', MAIL_TO] | |
# COMPOSE MESSAGE | |
msg = MIMEMultipart() | |
msg['Subject'] = SUBJECT | |
msg['From'] = EMAIL_FROM | |
#msg['Bcc'] = ', '.join(MAIL_TO) | |
# BODY | |
htmlBody = """\ | |
<html> | |
<head> | |
<style type="text/css"> | |
</style> | |
</head> | |
<body> | |
<img src="cid:attachTag" alt="Attached Imagef"> | |
</body> | |
</html> | |
""" | |
messageBody = MIMEText(htmlBody, 'html', 'utf-8') | |
msg.attach(messageBody) | |
# ATTACHMENT | |
attach = MIMEBase('application', "octet-stream") | |
attach.set_payload(open("full/path/to/file", "rb").read()) | |
Encoders.encode_base64(attach) | |
attach.add_header('Content-ID', '<attachTag>') | |
attach.add_header('Content-Disposition', 'attachment; filename="String Filename"') | |
msg.attach(attach) | |
# SERVER AND SEND | |
# ex: GMAIL | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.ehlo() | |
server.starttls() | |
server.login(username,password) | |
server.sendmail(EMAIL_FROM, MAIL_TO_LIST, msg.as_string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment