DJANGO - Problem sending email with From header equal to my alias of google apps account, not my self google apps account
العربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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_email(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?
Answer |
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.