我想在电子邮件中打印列表元素。
我在我的python脚本中定义了我的列表,如:
exceptions = []
在脚本末尾,列表将包含以下元素:
This is a boy.
This is a girl.
This is a dog.
我想打印名为'例外'的列表元素。在python脚本中设计的电子邮件中。
fromaddr = 'xxx@xxx.com'
toaddrs = 'xxx@xxx.com'
msg = """Subject:Big Bro FTP issue.
From: xxx@xxx.com
To: xxx@xxx.com
!!!PRINT THE EXCEPTION LIST HERE!!!
"""
print "Message length is " + repr(len(msg))
smtp_server = 'xxxxx.com'
smtp_username = 'xxxxxx'
smtp_password = 'xxxxxx'
smtp_port = '587'
smtp_do_tls = True
server = smtplib.SMTP(
host = smtp_server,
port = smtp_port,
timeout = 10
)
server.starttls()
server.ehlo()
server.login(smtp_username, smtp_password)
server.sendmail(fromaddr, toaddrs, msg)
print server.quit()
非常感谢任何帮助。
答案 0 :(得分:2)
我更喜欢MIMEText
import smtplib
from email.mime.multipart import MIMEText
msg = MIMEText("your_maeeage")
msg['From'] = <sender-email>
msg['To'] = <reciver-email>
msg['Subject'] = "your_subject"
server = smtplib.SMTP(<server>,<port>)
server.starttls()
server.login(Username,password)
server.sendmail(from_addr,to_addr,msg.as_string())
答案 1 :(得分:1)