我正在工作的联系形式,以接收来自用户的电子邮件。我使用的是EmailMessage(django 1.3)。问题是,我可以接收电子邮件,但“发件人”或“发件人”显示的是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()发布于 2012-08-16 11:20:38
Gmail不允许你作为任意的发送者发送邮件。
绕过这个问题的方法(我正在处理确切的问题:给我们发送电子邮件的客户服务表单)是使用一种非常便宜的SMTP服务,或者只是使用" reply-to“头,它仍然很有效(电子邮件来自me@gmail.com,但单击reply将指向reply- to地址)。
https://stackoverflow.com/questions/11979971
复制相似问题