# Python script to send mail via Apple's iCloud.  Be sure to setup an app specific password for and do not use or expose your iCloud password.  https://support.apple.com/en-us/HT204397

> Source: <https://gist.github.com/chrisswanda/57fbc7c587f76d8437880657c0893009>
> Published: 2020-10-29 11:06:35+00:00

smtp_icloud.py

      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      
Learn more about bidirectional Unicode characters

 
    Show hidden characters

import smtplib

#email.mime.multipart is specific to python3

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText

msg = MIMEMultipart()

msg['From'] = 'sendfrom@mail.com'

msg['To'] = 'sendto@mail.com'

msg['Subject'] = 'Subject'

message = 'Message body'

msg.attach(MIMEText(message))

mailserver = smtplib.SMTP('smtp.mail.me.com', 587)

# identify ourselves

mailserver.ehlo()

# secure our email with tls encryption

mailserver.starttls()

# re-identify ourselves as an encrypted connection

mailserver.ehlo()

mailserver.login('iCloud ID', 'app-specific password')

mailserver.sendmail('sendfrom@mail.com',

                    'sendto@mail.com', msg.as_string())

mailserver.quit()
