[英]Send an email in Python and include a vaiable in the subject line
我試圖在Python電子郵件腳本的主題行中包含一個變量,以將消息發送到手機。 當我運行程序時,消息中顯示“ The Temp is:CTemp”,但是我想要“ The Temp is:12.34”(或當時設置的變量)。 如何將變量CTemp插入主題行?
import smtplib
from email.mime.text import MIMEText
username = "****@****.com"
password = "****"
vtext = "**********@****.com"
CTemp = 12.34 #set for testing
msg = MIMEText
msg = MIMEText("""The Temp is: CTemp""")
server = smtplib.SMTP('****.****.net',25)
server.login(username,password)
server.sendmail(username, vtext, msg.as_string())
server.quit()
您應該將“文本”字符串連接到變量
CTemp = str(12.34) #set for testing
text = "The temp is: "+CTemp
msg = MIMEText(text)
http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.