smtplib
.main.py
import smtplib
from email.mime.text import MIMEText
TO_ADDRESS = "[email protected]"
FROM_ADDRESS = "[email protected]"
MY_PASSWORD = "Passwort für die Quelladresse"
def send_mail(msg):
try:
smtpobj = smtplib.SMTP('smtp.gmail.com', 587)
smtpobj.ehlo()
smtpobj.starttls()
smtpobj.ehlo()
smtpobj.login(FROM_ADDRESS, MY_PASSWORD)
smtpobj.sendmail(FROM_ADDRESS, TO_ADDRESS, msg.as_string())
smtpobj.close()
return True
except:
return False
if __name__ == '__main__':
msg = MIMEText("Testkörper")
msg['Subject'] = "Prüfung"
msg['From'] = FROM_ADDRESS
msg['To'] = TO_ADDRESS
result = send_mail(msg)
print(result)
pip3 install smtplib
python3 main.py
True
Recommended Posts