2012-08-16 59 views
0

我正在处理联系表单以接收来自用户的电子邮件。我使用的是EmailMessage(django 1.3)。问题是,我能够收到电子邮件,但'from'或'sender'显示email_host_user电子邮件,而不是用户的电子邮件。EmailMessage'发送者'问题

因此,如果用户的电子邮件地址[email protected],当我收到的电子邮件

from: [email protected] 
subject: some subject 
to: [email protected] 

,而不是

from: [email protected] 
subject: some subject 
to: [email protected] 

继承人的一部分设定

EMAIL_HOST = 'smtp.googlemail.com' 
EMAIL_HOST_PASSWORD = 'password' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_PORT = 587 
EMAIL_USE_TLS = True 
REVIEW_MODERATOR ='[email protected]' 

#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() 

回答

1

Gmail不会让您作为任意发件人发送。

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

+0

嘿感谢信息真正感谢它yuji。 – user1544778 2012-08-17 04:05:33