python SMTP

一。一開始,相信SMTP服務,因此在本機安裝了一個python

apt-get install sendmailsass

apt-get install sendmail-cf服務器

apt-get install squirrelmailui

apt-get install spamassassinspa

apt-get install mailman3d

apt-get install mailutilscode

apt-get install sharutilsblog

驗證SMTP完成utf-8

ps aux | grep sendmail
root 5980 0.0 0.2 102796 2676 ? Ss 18:34 0:00 sendmail: MTA: accepting connections
root 14091 0.0 0.0 15948 944 pts/25 S+ 21:46 0:00 grep --color=auto sendmailget

//test.py

import smtplib

from email.mime.text import MIMEText

from email.header import Header

 

sender = 'from@xxx.com'

receivers = ['791398105@qq.com']

 

message = MIMEText('mail send test...', 'plain', 'utf-8')

message['Subject'] = Header('Python SMTP mailtest', 'utf-8')

message['From'] = Header('my', 'utf-8')

message['To'] = Header('test', 'utf-8')

 

try:

        smtpObj = smtplib.SMTP('localhost')

        smtpObj.sendmail(sender, receivers, message.as_string())

        print 'succeed in sending'

except smtplib.SMTPException:

        print "Error: can not send mail"

試試效果

python test.py
succeed in sending

自我感受良好,可是QQ郵箱裏全空空也!!!!??????????????

what the fuck!!!

二。因而乎,本機python經過本機SMTP發送不成功

試試SMTP的mail命令吧,

echo "content" | mail -s subject 791398105@qq.com

成功了!,不過郵件在垃圾箱裏

如此看來,是python 使用了未更新的SMTP功能,而mail已是最新的了

那麼怎麼辦,因而網上轉轉吧!!!

什麼,最好連你的目的地址的SMTP服務器

OK,do it!

&得到QQ之SMTP的郵箱受權碼

發送短信,下邊的內容至指定號碼

選擇我已發送,收到受權碼

 

改變時效-無限期

最後,記得保存設置哦

&試試這個QQ的SMTP吧

//test1.py

import smtplib

from email.mime.text import MIMEText

from email.header import Header

 

mail_host="smtp.qq.com"

mail_user="791398105@qq.com"

mail_pass="***************" #your authorized code

 

 

sender='791398105@qq.com'

receivers=['791398105@qq.com']

 

message=MIMEText('Test sending mail for python','plain','utf-8')

message['From']=Header("my",'utf-8')

message['To']= Header("you",'utf-8')

 

subject='Test mail, please not open it'

message['Subject']=Header(subject,'utf-8')

 

try:

        smtpObj = smtplib.SMTP_SSL(mail_host,465)

        smtpObj.login(mail_user,mail_pass)

        smtpObj.sendmail(sender, receivers, message.as_string())

        smtpObj.quit()

        print "Succeed in sending mail"

except smtplib.SMTPException,e:

        print e

//result 

你看我收到了,並且仍是在正常的收件箱裏哦

Finally:

有時候,你想讓誰幹事,最好仍是直接告訴他,別拐彎抹角的,也許效果更好呢,對吧,你說呢?

相關文章
相關標籤/搜索