Skip to content

Instantly share code, notes, and snippets.

@HamGuy
Created May 27, 2015 01:24
Show Gist options
  • Save HamGuy/e65d0c5fddf7838d0e31 to your computer and use it in GitHub Desktop.
Save HamGuy/e65d0c5fddf7838d0e31 to your computer and use it in GitHub Desktop.
Send Mail With Python
#account info mation
sender = "[email protected]"
pwd = "xxxxxxxx"
receiver = "[email protected]"
subject = "Subject"
#get UpdateTips
fp = open(updateTipFileName,'rb')
mailContent = fp.read()
fp.close()
mailContent = mailContent.replace("versionNumber",versionNumber)
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiver
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
part = MIMEText(mailContent, 'html','utf-8')
msg.attach(part)
server = smtplib.SMTP_SSL('smtp.exmail.qq.com','465')
print "Login"
server.login(sender,pwd)
print "Start Send"
try:
server.sendmail(sender,receiver,msg.as_string())
print "Finish Send"
except Exception, e:
print "Failed"+e.message
finally:
server.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment