ich habe folgenden Code der soweit auch funktioniert:
Code: Alles auswählen
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
def send_email(filename, recipient_email):
sender_email = "no-reply@domain.de"
subject = "CSV-Datei als Anhang"
message = "Finden Sie anbei die angeforderte CSV-Datei"
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = recipient_email
msg['Subject'] = subject
msg.attach(MIMEText(message))
attachment = MIMEBase("application", "octet-stream")
with open(filename, "r") as file:
attachment.set_payload((file).read())
encoders.encode_base64(attachment)
attachment.add_header(
"Content-Disposition",
f"attachment; filename={filename}",
)
msg.attach(attachment)
smtp = smtplib.SMTP('mail.domain.de', 25)
#smtp.starttls()
smtp.sendmail(sender_email, recipient_email, msg.as_string())
smtp.quit()
send_email("liste.csv", "name@domain.de")
Code: Alles auswählen
send_email(r"\\domain.de\data\Rückfragen\liste.csv", "name@domain.de")
Viele Grüße
Knut