Questions tagged «smtplib»

13
如何使用python smtplib向多个收件人发送电子邮件?
经过大量搜索后,我无法找到如何使用smtplib.sendmail发送给多个收件人的方法。问题是每次发送邮件时,邮件标题似乎都包含多个地址,但实际上只有第一个收件人会收到电子邮件。 问题似乎在于email.Message模块期望的smtplib.sendmail()功能与功能不同。 简而言之,要发送给多个收件人,您应该将标题设置为以逗号分隔的电子邮件地址的字符串。但是,该sendmail()参数to_addrs应为电子邮件地址列表。 from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText import smtplib msg = MIMEMultipart() msg["Subject"] = "Example" msg["From"] = "me@example.com" msg["To"] = "malcom@example.com,reynolds@example.com,firefly@example.com" msg["Cc"] = "serenity@example.com,inara@example.com" body = MIMEText("example email body") msg.attach(body) smtp = smtplib.SMTP("mailhost.example.com", 25) smtp.sendmail(msg["From"], msg["To"].split(",") + msg["Cc"].split(","), msg.as_string()) smtp.quit()
196 python  email  smtp  message  smtplib 

11
如何使用Python发送电子邮件?
这段代码有效,并向我发送了一封电子邮件: import smtplib #SERVER = "localhost" FROM = 'monty@python.com' TO = ["jon@mycompany.com"] # must be a list SUBJECT = "Hello!" TEXT = "This message was sent with Python's smtplib." # Prepare actual message message = """\ From: %s To: %s Subject: %s %s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) …

7
Python:使用smtplib模块发送电子邮件时未显示“主题”
我可以使用smtplib模块成功发送电子邮件。但是,发送emial时,它不会在发送的电子邮件中包含主题。 import smtplib SERVER = <localhost> FROM = <from-address> TO = [<to-addres>] SUBJECT = "Hello!" message = "Test" TEXT = "This message was sent with Python's smtplib." server = smtplib.SMTP(SERVER) server.sendmail(FROM, TO, message) server.quit() 我应如何编写“ server.sendmail”以在发送的电子邮件中也包含主题。 如果使用server.sendmail(FROM,TO,消息,SUBJECT),则会显示有关“ smtplib.SMTPSenderRefused”的错误
70 python  smtplib 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.