我正在尝试在python 2.7中创建一个脚本,以将电子邮件发送给许多数据存储在文本文件中的人。
import smtplib
email = raw_input("Your Gmail: ")
password = raw_input("Your Gmail Password: ")
txtlist = raw_input(".txt file of receiver emails: ")
content = raw_input("Content of your email: ")
txt = open(txtlist, 'r')
read = txt.read()
read.split(",")
txt.close()
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login(email, password)
server.sendmail(email, read, content)
server.close()
运行脚本时,我希望它向文本文件中列出的所有人发送电子邮件。
当我运行脚本时,只会将电子邮件发送给列表中的第一个人。请帮忙,谢谢!
最佳答案
更换
read.split(",")
与
read = read.split(",")
这是示例(来自文档)
>>> import smtplib
>>> s=smtplib.SMTP("localhost")
>>> tolist= ["one@one.org","two@two.org","three@three.org","four@four.org"]
>>> msg = '''\
... From: Me@my.org
... Subject: testin'...
...
... This is a test '''
>>> s.sendmail("me@my.org",tolist,msg)
{ "three@three.org" : ( 550 ,"User unknown" ) }
>>> s.quit()
关于python - Python分割问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47746222/