【发布时间】:2020-02-10 07:37:41
【问题描述】:
我已经制作了一个表格,用户可以输入多个电子邮件地址,然后我的程序将向这些电子邮件地址发送一封邮件。我的程序确实收集了输入,但 SMTP 仅将其发送到一个电子邮件地址。我希望它一次将其发送到多个电子邮件地址。
这是我的代码:
def results():
userdata = request.form
quantity = userdata['quantity']
name = userdata['name']
email = userdata['email']
print(email)
msg = Message(subject="Hello", sender='populargifsontwitter@gmail.com', recipients=[email],
body="Hi!" + name + "This is a test email I sent with Gmail and Python!")
# calling mail and the send method and passing the message
mail.send(msg)
return render_template('results.html', quantity=quantity, email=email, name=name)
编辑:我被建议拆分它。
这就是我所做的:
email = email.split(",")
print(email)
for x in email:
msg = Message(subject="Hello", sender='populargifsontwitter@gmail.com', recipients= [x], body="Hi!"+name+"This is a test email I sent with Gmail and Python!" )
#calling mail and the send method and passing the message
mail.send(msg)
问题:现在电子邮件只会发送给第二个收件人,而不是第一个收件人。我应该怎么做,为什么它只发送给第二个收件人?
【问题讨论】:
-
您尝试过列表中的电子邮件吗?我建议你使用 mailgun API。
-
recipients获取一个或多个电子邮件地址的列表。您必须确保在将用户提供的电子邮件分配给recipients之前对其进行拆分。您是否还使用一封电子邮件对其进行了测试,以确保它可以正常工作。 -
我试图拆分它,但电子邮件被发送到第二个电子邮件地址而不是第一个。
标签: routes smtp flask-mail