我在配置我的 settings.py 时遇到困难,以便我可以使用任何发件人名称从网络服务器发送电子邮件
这就是我所做的:
EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.wservices.ch'
HOSTNAME = 'localhost'
DEFAULT_FROM_EMAIL = 'info@domain.com'
并像这样发送电子邮件:
html_content = render_to_string('htmlmail.html', {})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives('subject!',text_content,'info@domain.com',['to@domain.com'])
msg.attach_alternative(html_content, "text/html")
msg.send()
但我得到:
{('to@domain.com': (554, '5.7.1 <to@domain.com>: Relay access denied')}
在一个函数中,我有两个msg.send()
调用,顺便说一句。
我究竟做错了什么?
当我询问如何以编程方式从网络服务器发送邮件时,这是网站管理员的答案:
It is possible to send mails from E-Mail-Server "mail.wservices.ch".I suggest to
use the local installed Mail-Server. Hostname: localhost
There you can set any sender name, they just have to exist.
https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email