Skip to content

Instantly share code, notes, and snippets.

@pratikksinha
Forked from chrisswanda/smtp_icloud.py
Created November 7, 2021 15:17
Show Gist options
  • Save pratikksinha/68e292ede710d938a1281b91a192bfa5 to your computer and use it in GitHub Desktop.
Save pratikksinha/68e292ede710d938a1281b91a192bfa5 to your computer and use it in GitHub Desktop.
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
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'] = '[email protected]'
msg['To'] = '[email protected]'
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('[email protected]',
'[email protected]', msg.as_string())
mailserver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment