Skip to content

Instantly share code, notes, and snippets.

@brndnsvr
Forked from chrisswanda/smtp_icloud.py
Created November 26, 2022 12:44
Show Gist options
  • Select an option

  • Save brndnsvr/b428750fd9b92e8c6383d7d031a86a1d to your computer and use it in GitHub Desktop.

Select an option

Save brndnsvr/b428750fd9b92e8c6383d7d031a86a1d to your computer and use it in GitHub Desktop.

Revisions

  1. @chrisswanda chrisswanda revised this gist Oct 29, 2020. No changes.
  2. @chrisswanda chrisswanda revised this gist Oct 29, 2020. No changes.
  3. @chrisswanda chrisswanda created this gist Oct 29, 2020.
    25 changes: 25 additions & 0 deletions smtp_icloud.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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()