使用Python smtplib从.txt文件发送电子邮件到多个收件人 [英] Send Email to multiple recipients from .txt file with Python smtplib
本文介绍了使用Python smtplib从.txt文件发送电子邮件到多个收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从python发送邮件到多个电子邮件地址,从.txt文件导入,我尝试过不同的语法,但没有任何工作...
代码:
s.sendmail(sender@mail.com',['recipient@mail.com' 'recipient2@mail.com','recipient3@mail.com'],msg.as_string())
所以我尝试从.txt文件导入收件人地址:
urlFile = open(mailList.txt ,r +)
mailList = urlFile.read()
s.sendmail(sender@mail.com',mailList,msg.as_string())
mainList.txt包含:
['recipient@mail.com','recipient2@mail.com','recipient3@mail.com']
但它不工作...
我也试图做:
... [mailList] ...在代码中,'...','...','...'在.txt文件中,但也没有EFFE ct
和
code> ... [mailList] ...在代码中,...','...',...在.txt文件中,但也没有影响... $ b $有没有人知道该怎么办?
谢谢很多!
解决方案
urlFile = open(mailList.txt,r +)
mailList = [i.strip()for i in urlFile.readlines()]
并将每个收件人放在自己的行(即分开换行)。
I try to send mails from python to multiple email-addresses, imported from a .txt file, I've tried differend syntaxes, but nothing would work...
The code:
s.sendmail('sender@mail.com', ['recipient@mail.com', 'recipient2@mail.com', 'recipient3@mail.com'], msg.as_string())
So I tried this to import the recipient-addresses from a .txt file:
urlFile = open("mailList.txt", "r+") mailList = urlFile.read() s.sendmail('sender@mail.com', mailList, msg.as_string())
The mainList.txt contains:
['recipient@mail.com', 'recipient2@mail.com', 'recipient3@mail.com']
But it doesn't work...
I've also tried to do:
... [mailList] ... in the code, and '...','...','...' in the .txt file, but also no effect
and
... [mailList] ... in the code, and ...','...','... in the .txt file, but also no effect...
Does anyone knows what to do?
Thanks a lot!
解决方案urlFile = open("mailList.txt", "r+") mailList = [i.strip() for i in urlFile.readlines()]
and put each recipient on its own line (i.e. separate with a line break).
这篇关于使用Python smtplib从.txt文件发送电子邮件到多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文