Tried a lot of times can not succeed, and then find this to send successfully!
#!/usr/bin/python
#coding: Utf-8
Import Smtplib
From Email.mime.text import Mimetext
From email.utils import formataddr
My_sender= "
My_user= "
DEF Mail ():
Ret=true
Try
Msg=mimetext (' fill in message contents ', ' Plain ', ' utf-8 ')
msg[' from ']=formataddr (["aaa", my_sender])
msg[' to ']=formataddr (["bbb", my_user])
msg[' Subject ']= "bbb"
Server=smtplib. SMTP ("smtp.163.com") #发件人邮箱中的SMTP服务器, Port is 25
Server.login (my_sender, "")
Server.sendmail (my_sender,[my_user,],msg.as_string ()) #括号中对应的是发件人邮箱账号, recipient's Email account, Email
Server.quit () #这句是关闭连接的意思
Except Exception: #如果try中的语句没有执行, The following ret=false is executed
Ret=false
return ret
Ret=mail ()
If Ret:
Print ("ok") #如果发送成功则会返回ok, wait 20 seconds or so to receive mail
Else
Print ("filed") #如果发送失败则会返回filed
Python Send mail script