在django中添加电子邮件标题

时间:2017-08-26 20:02:32

标签: django

所以我在views.py

中有这样的代码
pip install -e ~/Repositories/some_local_fork_repo_path/

我想添加标题'List-Unsubscribe',但它不起作用,我收到服务器错误。如果我使用'#'代码,代码工作正常。如何添加此标题?感谢。

1 个答案:

答案 0 :(得分:4)

您可以尝试使用EmailMessage

from django.core.mail import EmailMessage


email = EmailMessage(
    'subject',
    'message.',
    'info@xyz1234.de',
    to=['MYTEST@yandex.ru'],
    headers={'MY-UNIQUE-HEAD':  '<http://www.xyz1234.de/unsubscribe123'},
)

email.send(fail_silently=False)

设置

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'YOURUSER@gmail.com'
EMAIL_HOST_PASSWORD = 'YOURPASS'

enter image description here