生活随笔
收集整理的這篇文章主要介紹了
腾讯云使用Python发邮件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
寫在前面
我購(gòu)買的騰訊云默認(rèn)自帶Python3.6.8版本,但是我自己重新編譯安裝了Python3.6.0版本
環(huán)境準(zhǔn)備
[ root@VM-0-17-centos ~
]
[ root@VM-0-17-centos ~
]
[ root@VM-0-17-centos ~
]
[ root@VM-0-17-centos Python-3.6.0
]
[ root@VM-0-17-centos ~
]
[ root@VM-0-17-centos ~
]
lrwxrwxrwx 1 root root 9 Aug 14 11:53 /usr/local/bin/python3 -
> python3.6
將要發(fā)送郵件的郵箱授權(quán) 以163郵箱為例:
開啟SMTP服務(wù),用手機(jī)發(fā)送號(hào)碼進(jìn)行授權(quán),記得保存授權(quán)碼!!
import smtplib
from email
. header
import Header
from email
. mime
. text
import MIMEText
host
= "smtp.163.com"
port
= 465
user
= "xxxxxxxx@163.com"
password
= "xxxxxxxxxxx"
sender
= "xxxxxxxxxxxx@163.com"
receivers
= [ "xxxxxx@163.com" , 'xxxxxx@163.com' , 'xxxxxx@163.com' , "xxxxxx@163.com" , "xxxxxx@163.com" , "xxxxxx@163.com" ] content
= ''' 這是一封測(cè)試郵件內(nèi)容隨你喜歡隨便寫
'''
subject
= '測(cè)試郵件'
def send_email ( ) : msg
= MIMEText
( content
+ '\n send_email' , 'plain' , 'utf-8' ) msg
[ 'From' ] = usermsg
[ 'To' ] = ',' . join
( receivers
) msg
[ 'Subject' ] = subject
+ ' send_email' try : smtpObj
= smtplib
. SMTP_SSL
( host
, port
) smtpObj
. login
( user
, password
) smtpObj
. sendmail
( sender
, receivers
, msg
. as_string
( ) ) print ( "郵件發(fā)送成功" ) except smtplib
. SMTPException
as e
: print ( e
) if __name__
== '__main__' : send_email
( )
總結(jié)
以上是生活随笔 為你收集整理的腾讯云使用Python发邮件 的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔 推薦給好友。