我有一个应用程序将发送数千封电子邮件。我最初的计划是遍历每条记录并一次发送一封电子邮件,然后从记录的 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>