Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/local/bin/python
- SMTPserver = 'smtp.sina.com'
- sender = '<milanlanlanlan@sina.com>'
- destination = ['1291023320@qq.com']
- USERNAME = "milanlanlanlan@sina.com"
- PASSWORD = "*******"
- # typical values for text_subtype are plain, html, xml
- text_subtype = 'plain'
- content="""\
- Test message
- """
- subject="Sent from Python"
- import sys
- import os
- import re
- from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
- # from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
- # old version
- # from email.MIMEText import MIMEText
- from email.mime.text import MIMEText
- try:
- msg = MIMEText(content, text_subtype)
- msg['Subject']= subject
- msg['From'] = sender # some SMTP servers will do this automatically, not all
- conn = SMTP(SMTPserver, 465)
- conn.set_debuglevel(False)
- conn.login(USERNAME, PASSWORD)
- try:
- conn.sendmail(sender, destination, msg.as_string())
- finally:
- conn.quit()
- print "Send successfully!"
- except Exception, exc:
- sys.exit( "mail failed; %s" % str(exc) ) # give a error message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement