Salut à tous
J'ai bricolé en pompant à droite, gauche un script qui me permet de faire un mail avec une pièce jointe mais j'aimerai envoyé plusieurs, je cherche mais une petite aide je dit pas non
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import os.path
email = 'LE MAIL'
password = 'MDP'
send_to_email = 'LE MAIL DESTINATAIRE'
subject = 'TITRE MAIL'
message = 'LE TEXTE DU MESSAGE '
file_location = "chemin de la pièce jointe"
msg = MIMEMultipart()
msg['From'] = email
msg['To'] = send_to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
# Setup the attachment
filename = os.path.basename(file_location)
attachment = open(file_location , "rb")
part = MIMEBase('application', 'pdf')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
# Attach the attachment to the MIMEMultipart object
msg.attach(part)
server = smtplib.SMTP('smtp.office365.com', 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, send_to_email, text)
server.quit()
