質問

I have a question about sending emails in Python to recipients who will be viewing them in the Apple Mail client. I'll be sending emails from my gmail account to people who will be viewing them in Apple Mail. I'm trying to make sure the recipients, my coworkers, see only the sender I intend for them to see, an alias for my office email. When viewed through Apple Mail, though, the email shows both the sender I define and the actual sending address. Here's what I'm running:

import smtplib
from email.mime.text import MIMEText
msg = MIMEText('Warning, deadline X approaching.')
msg['To'] = 'recipient@theoffice.com'
msg['Subject'] = 'Deadline Issues'
msg['From'] = 'automatedwarning@theoffice.com'
msg['From'] = 'automatedwarning@theoffice.com'
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()
server.login('sender','password')
server.sendmail('sender@gmail.com','recipient@theoffice.com',msg.as_string())
server.quit()

The sender is shown as automatedwarning@theoffice.com in all clients except Apple Mail, in which both sender@gmail.com and automatedwarning@theoffice.com are listed. So, how and, if possible, why?

Also, why do I have to set the sender twice to get the displayed sender to change? If I set it only once, it doesn't change in any client.

Thanks for your help!

役に立ちましたか?

解決

When you use Google as an SMTP server, it will set the from address to your address. You should consider a commercial solution (like sendgrid or mailchimp's mandrill service.)

http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top