Search code examples
pythongmailsmtplib

Apple Mail Lists Senders Beyond Defined Senders


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'] = '[email protected]'
msg['Subject'] = 'Deadline Issues'
msg['From'] = '[email protected]'
msg['From'] = '[email protected]'
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()
server.login('sender','password')
server.sendmail('[email protected]','[email protected]',msg.as_string())
server.quit()

The sender is shown as [email protected] in all clients except Apple Mail, in which both [email protected] and [email protected] 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!


Solution

  • 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