Projekt

E-Mail mit Python und Gmail versenden

image_print

App Passwort im Google Account erstellen (mit dem primären Gmail Account Passwort geht es nicht!):

Python Script erstellen:

import smtplib

gmail_user = 'hanswurst@gmail.com'
gmail_app_password = 'meinsicherespasswort'

sent_from = gmail_user
to = ['bill.gates@linformatik.de', 'hanswurst@gmail.com']
subject = 'Test Mail Python'
body = 'hallo welt'

email_text = """\
From: %s
To: %s
Subject: %s

%s
""" % (sent_from, ", ".join(to), subject, body)

try:
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.ehlo()
    server.login(gmail_user, gmail_app_password)
    server.sendmail(sent_from, to, email_text)
    server.close()

    print ('Mail erfolgreich versendet')
except:
    print ('Etwas lief schief...')
Quelle: https://stackabuse.com/how-to-send-emails-with-gmail-using-python/

Posteingang checken:

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert