cd /news/developer-tools/python-script-to-send-mail-via-apple… · home topics developer-tools article
[ARTICLE · art-10234] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

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

This article provides a Python script that uses the `smtplib` library to send emails through Apple's iCloud SMTP server (`smtp.mail.me.com` on port 587). The script establishes a TLS-encrypted connection, logs in using an iCloud ID and an app-specific password (not the user's main iCloud password), and sends a MIME-formatted email with a subject and body. It emphasizes the importance of creating an app-specific password for security and avoiding exposure of the primary iCloud password.

read1 min views18 publishedOct 29, 2020

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)


mailserver.ehlo()


mailserver.starttls()


mailserver.ehlo()

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

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

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

mailserver.quit()
── more in #developer-tools 4 stories · sorted by recency
── more on @apple 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/python-script-to-sen…] indexed:0 read:1min 2020-10-29 ·