我正在处理联系表单以接收用户的电子邮件。我正在使用EmailMessage(django 1.3)。问题是,我能够收到电子邮件,但'from'或'sender'显示email_host_user电子邮件而不是用户的电子邮件。
所以,如果用户有电子邮件地址user@gmail.com,我收到电子邮件
from: email@gmail.com
subject: some subject
to: moderator@email.com
而不是
from: user@gmail.com
subject: some subject
to: moderator@email.com
这是设置的一部分
EMAIL_HOST = 'smtp.googlemail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
REVIEW_MODERATOR ='moderator@email.com'
#heres part of the helpers.py
def run(self):
html = get_template(self.kwargs['template'])
html_content = html.render(Context(self.kwargs['context']))
msg = EmailMessage(
self.kwargs['subject'],
html_content,
self.kwargs['sender'],
[self.kwargs['email']],
bcc=[a[1] for a in settings.ADMINS])
msg.content_subtype = "html" # Main content is now text/html
try:
path = self.kwargs['file_path']
except KeyError:
pass
else:
msg.attach_file(path)
msg.send()
#heres part of the contact view
if contact_form.is_valid():
cdata = contact_form.cleaned_data
c={'name':cdata['name'], 'email':cdata['email'],'message':cdata['message']}
EmailThread(**{
'email':settings.REVIEW_MODERATOR,
'sender':cdata['email'],
'subject':email_subject,
'context':c,
'template':template
}).start()
答案 0 :(得分:1)
Gmail不允许您以任意发件人身份发送邮件。
解决这个问题的方法(我正在处理确切的问题:向我们发送电子邮件的客户服务表单)是使用非常便宜的SMTP服务之一,或者只使用仍然相当的“回复”标题功能(电子邮件来自me@gmail.com,但点击回复将指向回复地址)。