Reputation: 522
I have an email account at Google Apps, ([email protected]), and for this account I created an alias([email protected]).
My intention is to send email through my account([email protected]) but using the alias([email protected]) at 'From' header.
The following Django code shows what I'm trying to do:
params = {
'host' : "smtp.gmail.com",
'port' : 587,
'username' : "[email protected]",
'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", "[email protected]", "[email protected]")
The problem is that when "foo" receives my message he doesn't see myalias@mydomain, as remitent, he sees [email protected] instead.
I checked the raw message and I don't see any part of the original message including the email [email protected] in the headers. Any idea what could be wrong here?
Upvotes: 4
Views: 1001
Reputation: 416
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.
Upvotes: 3