开发者

Problem sending email with From header equal to my alias of google apps account, not my self google apps account

I have an email account at Google Apps, (myaccount@mydomain.com), and for this account I created an alias(myalias@mydomain.com).

My intention is to send email through my account(myaccount@mydomain.com) but using the alias(myalias@mydomain.com) at 'From' header.

The following Django code shows what I'm trying to do:

params = {
  'host' : "smtp.gmail.com",
  'port' : 587,
  'username' : "myaccount@mydomain.com",
  'password' : "12345",  #my pass for myaccount
  'use_tls' : True,
}
connection=get_connection('django.core.mail.backends.smtp.EmailBackend',**params)

def send_emai开发者_运维知识库l(subject, body, from_email, to):
  headers={
    'From': from_email,
  }
  email = EmailMultiAlternatives(subject=subject, 
                                 body=body, 
                                 from_email=from, 
                                 to=[to],
                                 connection=connection,
                                 headers=headers)
  return email.send()

send_email("testing", "Hi, my friend", "myalias@mydomain.com", "foo@bardomain.com")

The problem is that when "foo" receives my message he doesn't see myalias@mydomain, as remitent, he sees myaccount@mydomain.com instead.

I checked the raw message and I don't see any part of the original message including the email myalias@mydomain.com in the headers. Any idea what could be wrong here?


As you have tagged google-apps, I assume you are using Google as your SMTP server. By default google sends from the primary account.

To change this, login to the gmail interface, go to the Settings, and choose Accounts.

You should have a group called send mail as - add the alias you want to use to that list & the Django mails should come through as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜