Python 實現SMTP發送郵件

import smtplib

    #設置收件人、發件人

smtpDstAddr = "[email protected]"

smtpSrcAddr = "[email protected]"

    #設置SMTP服務器信息

smtpServer = "smtp.qq.com"

smtpPwd = "123456789"

smtpPort = 587

    #構建郵件內容

mailSubject = "Raspberry Pi SMTP"

mailText = "This is a test mail from a RABBIT!"

mailMsg =   "To: " + smtpDstAddr + "\n" + \

            "From: " + smtpSrcAddr + "\n" + \

            "Subject: " + mailSubject + "\n" + \

            "\n" + mailText + "\n"


    #啓動郵件發送流程

    #print "Connecting to SMTP server %s (port: %d)..." %(smtpServer, smtpPort) 

mySMTP = smtplib.SMTP(smtpServer, smtpPort)

    #print "Starting transport layer security..."

mySMTP.starttls() # Transport layer security

    #print "Processing login..."

mySMTP.login(smtpSrcAddr, smtpPwd)

    #print "Sending the mail..."

mySMTP.sendmail(smtpSrcAddr, smtpDstAddr, mailMsg)

    #print "Closing STMP..."

mySMTP.close

    #print "OK!"

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章