36 lines
945 B
Python
36 lines
945 B
Python
#!/usr/bin/env python3
|
|
import smtplib
|
|
import ssl
|
|
|
|
# Fabrication du corps du email_passwordMessage
|
|
sender = "peinture-dumas@entreprise-dumas.com"
|
|
receiver = "phuoc@caotek.fr"
|
|
message = """\
|
|
Subject: Envoi d'un message en TLS
|
|
|
|
Voici le contenu du message. Phuoc"""
|
|
|
|
# Create a secure SSL context
|
|
context = ssl.create_default_context()
|
|
smtp_server = "smtp.office365.com"
|
|
smtp_port = 587 # For TLS
|
|
smtp_user = "peinture-dumas@entreprise-dumas.com"
|
|
smtp_pass = "Nar50611"
|
|
|
|
# Try to log in to server and send email
|
|
try:
|
|
server = smtplib.SMTP(smtp_server,smtp_port)
|
|
# server.ehlo() # Can be omitted
|
|
server.starttls(context=context) # Secure the connection
|
|
# server.ehlo() # Can be omitted
|
|
server.login(smtp_user, smtp_pass)
|
|
# envoyer l'email
|
|
server.sendmail(sender, receiver, message)
|
|
print("sendmail -> OK")
|
|
|
|
except Exception as e:
|
|
# Print any error messages to stdout
|
|
print(e)
|
|
finally:
|
|
server.quit()
|