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!"