smtplib
.main.py
import smtplib
from email.mime.text import MIMEText
TO_ADDRESS = "Adresse de [email protected]"
FROM_ADDRESS = "Adresse [email protected]"
MY_PASSWORD = "Mot de passe de l'adresse source"
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("Corps de test")
msg['Subject'] = "tester"
msg['From'] = FROM_ADDRESS
msg['To'] = TO_ADDRESS
result = send_mail(msg)
print(result)
pip3 install smtplib
python3 main.py
True
Recommended Posts