0

我正在制作一个联系表格来接收来自用户的电子邮件。我正在使用 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()
4

1 回答 1

1

Gmail 不允许您以任意发件人的身份发送邮件。

解决这个问题的方法(我正在处理确切的问题:向我们发送电子邮件的客户服务表格)是使用一种非常便宜的 SMTP 服务,或者只是使用仍然非常实用的“回复”标题(电子邮件来自 me@gmail.com 但单击回复将指向回复地址)。

于 2012-08-16T03:20:37.943 回答