-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.py
executable file
·49 lines (39 loc) · 1.5 KB
/
send.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from email.mime.text import MIMEText
import smtplib
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def mail(recipient_email, sender_email, password, body, fichier_piece_jointe):
# Paramètres du serveur SMTP Gmail
smtp_server = 'smtp-mail.outlook.com'
smtp_port = 587 # Port TLS
# Votre adresse e-mail Gmail et mot de passe
# Création de l'e-mail
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = recipient_email
msg['Subject'] = 'XRETAIL'
# Attacher le fichier
with open(fichier_piece_jointe, 'rb') as piece_jointe:
mime_part = MIMEBase('application', 'octet-stream')
mime_part.set_payload(piece_jointe.read())
encoders.encode_base64(mime_part)
mime_part.add_header('Content-Disposition', f'attachment; filename={fichier_piece_jointe}')
msg.attach(mime_part)
msg.attach(MIMEText(body, 'plain'))
# Connexion au serveur SMTP
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
# Authentification
server.login(sender_email, password)
# Envoi de l'e-mail
server.sendmail(sender_email, recipient_email, msg.as_string())
# Fermeture de la connexion SMTP
server.quit()
print("E-mail envoyé avec succès !")
#mail(recipient_email, sender_email, password, body)