我在setting.py
文件中有这个:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'from@gmail.com'
EMAIL_HOST_PASSWORD = 'Pass'
我想向通过模板发布的目的地发送电子邮件:
from django.core.mail.message import EmailMessage
destinations = request.POST['destinations'] #this return string with 2 emails ('fst@gmail.com; sd@gmail.com')
EmailMessage(subject, core, to=[destinations]).send()
它只发送电子邮件到第一封邮件而不是其他人! 是否有任何行动使这项工作适用于所有发布的电子邮件?
答案 0 :(得分:1)
将列表传递给to
:
import re
# or you can use request.getlist('destination')
# I do not know how you generate the two mail addresses
destinations = re.split(r'[;\s]*', request.POST['destinations'])
EmailMessage(subject, content, to=destinations)