【发布时间】:2026-02-01 11:50:01
【问题描述】:
我有一个要发送数千封电子邮件的应用程序。我最初的计划是遍历每条记录并一次发送一封电子邮件,然后从记录的 UUID 创建取消订阅链接。为了加快发送电子邮件的速度,我改用 EmailMultiAlternative 和 get_connection() 只需要构建一个上下文
email = EmailMultiAlternatives()
email.subject = email_script.subject
email.from_email = DEFAULT_FROM_EMAIL
template = get_template('email/email_blast_template.html')
......
body = template.render(context)
connection = get_connection()
connection.open()
email.bcc = list(recipients)
email.body = body
email.attach_alternative(body, "text/html")
email.connection = connection
email.send()
connection.close()
我是否可以访问正在发送的每封电子邮件的电子邮件地址,以便建立退订链接? request.META 中是否存储了信息?我很难看到里面有什么。
If you wish to unsubscribe click <a href={% url unsubscribe email.uuid }}>here</a>
【问题讨论】:
标签: python django django-templates django-email