Fixes in sendmail

This commit is contained in:
Antonio de la Rosa 2025-11-15 13:26:15 +01:00
parent e0dd761956
commit 22a964f0f5

View file

@ -29,6 +29,7 @@ from email.mime.base import MIMEBase
from email.mime.image import MIMEImage from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import formataddr
import ssl as ssl_module import ssl as ssl_module
import sys import sys
@ -129,7 +130,7 @@ class SendMail:
return True return True
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]): def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[], reply_to=()):
""" Method that send email """ Method that send email
With this method you can send email to multiple address, html, and add attachments to email With this method you can send email to multiple address, html, and add attachments to email
@ -147,6 +148,10 @@ class SendMail:
if not self.connect(): if not self.connect():
return False return False
if len(reply_to)==0:
reply_to=(from_address, from_address)
COMMASPACE=', ' COMMASPACE=', '
if len(attachments)==0: if len(attachments)==0:
@ -154,6 +159,9 @@ class SendMail:
msg=MIMEText(message, content_type) msg=MIMEText(message, content_type)
msg['Subject']=subject msg['Subject']=subject
msg['Reply-To']=formataddr(reply_to)
msg['From']=from_address msg['From']=from_address
msg['To']=COMMASPACE.join(to_address) msg['To']=COMMASPACE.join(to_address)
@ -169,6 +177,9 @@ class SendMail:
outer=MIMEMultipart() outer=MIMEMultipart()
outer['Subject']=subject outer['Subject']=subject
msg['Reply-To']=formataddr(reply_to)
outer['From']=from_address outer['From']=from_address
outer['To']=COMMASPACE.join(to_address) outer['To']=COMMASPACE.join(to_address)