Rev 1180 | Rev 2123 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/pythonimport smtplibfrom email.MIMEMultipart import MIMEMultipartfrom email.MIMEBase import MIMEBasefrom email.MIMEText import MIMETextfrom email import Encodersimport osdef get_attachment_part(filename):part = MIMEBase('application', 'octet-stream')part.set_payload(open(filename, 'rb').read())Encoders.encode_base64(part)part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))return partdef mail(from_user, from_pwd, to, subject, text, part=None):msg = MIMEMultipart()msg['From'] = from_usermsg['To'] = tomsg['Subject'] = subjectmsg.attach(MIMEText(text))if part:msg.attach(part)mailServer = smtplib.SMTP("smtp.gmail.com", 587)mailServer.ehlo()mailServer.starttls()mailServer.ehlo()mailServer.login(from_user, from_pwd)mailServer.sendmail(from_user, to, msg.as_string())# Should be mailServer.quit(), but that crashes...mailServer.close()if __name__ == '__main__':mail("cnc.center@shop2020.in","puttherightpasswdhere","some.person@some.address.com","Hello from python!","This is an email sent with python",None)