任何人都知道如何解决我的问题,我与多个收件人DJango电子邮件工作。从我的数据库向多个收件人帐户发送电子邮件正在工作,但现在我想发送电子邮件,电子邮件:正文取决于数据ID
这是电子邮件列表
场景:车牌号123123将发送至示例_email1@gmail.com仅和ABV112将再次发送到示例_email2@gmail.com等等只有在电子邮件中没有分配的车牌才会发送,有人可以帮我解决我的问题。谢谢大家!
auto send email script:
class HomeView(ListView):
cstatus = VR.objects.filter(Deadline__date = datetime.datetime.today(), sent_email="No")
print(cstatus)
recipient_list = []
for recipient in cstatus:
recipient_list.append(recipient.email)
print(recipient_list)
plate = ""
for carreg in cstatus:
print(carreg.plate_no)
plate = carreg.plate_no
if plate != "":
subject = 'FMS Automated Email'
html_message = render_to_string('vr/pms_email.html', {'content':cstatus})
plain_message = strip_tags(html_message)
from_email = 'FMS <fms@gmail.com>'
mail.send_mail(subject, plain_message, from_email, recipient_list, html_message=html_message, fail_silently=False)
cstatus.update(sent_email="Yes")
model = VR
context_object_name = 'list'
template_name = 'vr/list.html'
根据我对您的查询的理解,这可能是您需要的:
或使用django中的群发电子邮件:
链接:https://docs.djangoproject.com/en/1.8/topics/email/#send-mass-mail
将上述所有消息结果添加到一个元组中,并将其添加到send_mass_mail中。例如
如果我错了,请告诉我。
您可以在cstatus查询集上使用for循环将电子邮件发送给收件人。没有测试它,但它应该是这样的:
相关问题 更多 >
编程相关推荐