import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
import os
def mail_stuff():
"""
mail stuff to gmail account cause you can't do ssh or scp from coursera
"""
user_id="xxx"
password = "xxx"
outer = MIMEMultipart()
outer['Subject'] = 'files from coursera'
outer['To'] = "dougchang25@gmail.com"
outer['From'] = "dougchang25@gmail.com"
outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
attachments = ['images/classification_kiank.png']
for file in attachments:
try:
with open(file, 'rb') as fp:
msg = MIMEBase('application', "octet-stream")
msg.set_payload(fp.read())
encoders.encode_base64(msg)
msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(file))
outer.attach(msg)
except:
print("Unable to open one of the attachments. Error: ", sys.exc_info()[0])
raise
composed = outer.as_string()
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(user_id, password)
server.sendmail(user_id, user_id, composed)
server.close()
print("sent!!!!")
except:
print ('Something went wrong...')
mail_stuff()
Thanks for the information... I really love your blog posts..
ReplyDeleteartificial intelligence internship | best final year projects for cse | internship certificate online | internship for mba finance students | internship meaning in tamil