94 lines
2.1 KiB
Python
94 lines
2.1 KiB
Python
import smtplib
|
|
from email.mime.text import MIMEText
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
SMTP_SERVER = "mail.mj91.fr" # ou ton serveur SMTP Synology / OVH
|
|
SMTP_PORT = 587 # 587 avec STARTTLS, ou 465 en SSL
|
|
SMTP_USER = "services" # adresse expéditrice
|
|
SMTP_PASSWORD ="84Bf&c$$1Mx953s8!L2"
|
|
import smtplib
|
|
from email.mime.text import MIMEText
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
FROM_EMAIL = "services@domo91.fr"
|
|
TO_EMAIL = "robots@domo91.fr"
|
|
|
|
msg = MIMEMultipart()
|
|
msg["From"] = FROM_EMAIL
|
|
msg["To"] = TO_EMAIL
|
|
msg["Subject"] = "Test mail depuis la VM"
|
|
|
|
body = """
|
|
Bonjour,
|
|
|
|
Ceci est un test d'envoi de mail depuis la VM en SSH.
|
|
|
|
Si tu reçois ce message, l'envoi SMTP fonctionne.
|
|
|
|
Michel
|
|
"""
|
|
|
|
msg.attach(MIMEText(body, "plain"))
|
|
|
|
try:
|
|
print("Connexion au serveur SMTP...")
|
|
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT, timeout=20)
|
|
server.set_debuglevel(1)
|
|
|
|
print("Démarrage TLS...")
|
|
server.starttls()
|
|
|
|
print("Authentification...")
|
|
server.login(SMTP_USER, SMTP_PASSWORD)
|
|
|
|
print("Envoi du message...")
|
|
server.sendmail(FROM_EMAIL, TO_EMAIL, msg.as_string())
|
|
|
|
server.quit()
|
|
print("✅ Mail envoyé avec succès")
|
|
|
|
except Exception as e:
|
|
print("❌ Erreur lors de l'envoi :")
|
|
print(e)
|
|
|
|
FROM_EMAIL = "services@domo91.fr"
|
|
TO_EMAIL = "robots@domo91.fr"
|
|
|
|
msg = MIMEMultipart()
|
|
msg["From"] = FROM_EMAIL
|
|
msg["To"] = TO_EMAIL
|
|
msg["Subject"] = "Test mail depuis la VM"
|
|
|
|
body = """
|
|
Bonjour,
|
|
|
|
Ceci est un test d'envoi de mail depuis la VM en SSH.
|
|
|
|
Si tu reçois ce message, l'envoi SMTP fonctionne.
|
|
|
|
Michel
|
|
"""
|
|
|
|
msg.attach(MIMEText(body, "plain"))
|
|
|
|
try:
|
|
print("Connexion au serveur SMTP...")
|
|
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT, timeout=20)
|
|
server.set_debuglevel(1)
|
|
|
|
print("Démarrage TLS...")
|
|
server.starttls()
|
|
|
|
print("Authentification...")
|
|
server.login(SMTP_USER, SMTP_PASSWORD)
|
|
|
|
print("Envoi du message...")
|
|
server.sendmail(FROM_EMAIL, TO_EMAIL, msg.as_string())
|
|
|
|
server.quit()
|
|
print("✅ Mail envoyé avec succès")
|
|
|
|
except Exception as e:
|
|
print("❌ Erreur lors de l'envoi :")
|
|
print(e)
|