Last active
December 24, 2015 05:19
-
-
Save ranlix/6749910 to your computer and use it in GitHub Desktop.
用smtplib来登录连接邮箱,发送测试邮件到目标邮件
This file contains 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
# -*- coding:utf-8 -*- | |
import smtplib | |
username = "*******@163.com" | |
password = "*********" | |
smtp = smtplib.SMTP() #继承SMTP()的属性 | |
smtp.connect("smtp.163.com","25") #连接服务器和端口 | |
mail_text = """ | |
From: *******@163.com\r\n | |
To: [email protected]\r\n | |
Subject: This is a email with Python\r\n | |
""" | |
try: | |
smtp.login(username,password) | |
print "Login sucess!" | |
except: | |
print "Cannot login email, please check your username and password!" | |
try: | |
smtp.sendmail("*******@163.com","[email protected]",mail_text) | |
smtp.quit() | |
print "Sucess!" | |
except: | |
print "cannot send the mail!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment