gpt4 book ai didi

python - Python 中的分割问题

转载 作者:太空宇宙 更新时间:2023-11-03 14:24:03 24 4
gpt4 key购买 nike

我正在尝试用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com