标签:
使用Python的smtp模块,可以十分方便的编写自己的smtp客户端,来发送邮件。现在发现,不能使用腾讯的smtp服务器去法送,但是可以使用163的smtp服务器去发送邮件。
直接上代码吧
#!/usr/bin/env python
‘‘‘
a simple smtp client
‘‘‘
import smtplib
from email.mime.text import MIMEText
def sendMail(user,pwd,to,subject,text):
msg=MIMEText(text)
msg[‘From‘]=user
msg[‘To‘]=to
msg[‘Subject‘]=subject
try:
smtpServer=smtplib.SMTP(‘smtp.qq.com‘,587)#Configure 1
#smtpServer=smtplib.SMTP(‘smtp.163.com‘,587)#Configure 2
print "[+] Connecting To Mail Server"
smtpServer.ehlo()
print "[+] Starting Encrypted Session"
smtpServer.starttls()
smtpServer.ehlo()
print "[+] Logging Into Mail Server"
smtpServer.login(user,pwd)
print "[+] Logging successfully"
print "[+] Sendding Mail"
smtpServer.sendmail(user,to,msg.as_string())
smtpServer.close()
print "[+] Mail send Successfully"
except:
print "[+] Mail send failed"
def main():
‘Configure 1: from qq mail to 163 mail‘
user=""#type in your own qq email account
pwd=""#type in your own qq email pwd
to=""#type in your own 163 email account
‘Configure 2: from 163 mail to qq mail‘
#user=""#type in your own 163 email account
#pwd=""#type in your own 163 email pwd
#to=""#type in your own qq email account
subject="test my client"
text="test test test"
sendMail(user,pwd,to,subject,text)
if __name__=="__main__":
main()
填写自己的邮件地址和目的邮件地址,就可以轻松使用自己的smtp客户端了。
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/wolfzhaoshuai/article/details/46879619