Skip to content

Commit 1cbbde6

Browse files
committed
Added: improved mail features (#9)
1 parent 8f461f6 commit 1cbbde6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libreforms_fastapi/utils/smtp.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ def __init__(self, mail_server=None, port=None,
2222

2323
# borrowed shamelessly from
2424
# https://www.aabidsofi.com/posts/sending-emails-with-aws-ses-and-python/
25-
def send_mail(self, subject=None, content=None, to_address=None, cc_address_list=[], logfile=None):
25+
def send_mail(self, subject=None, content=None, to_address=None, cc_address_list=[], logfile=None, reply_to_addr=None):
2626

2727
# only if we have enabled SMTP
2828
if self.enabled:
29+
30+
cc_conditions = all([
31+
cc_address_list,
32+
isinstance(cc_address_list, list),
33+
len(cc_address_list)>0
34+
])
35+
2936
try:
3037
# creating an unsecure smtp connection
3138
with smtplib.SMTP(self.mail_server,self.port) as server:
@@ -35,7 +42,8 @@ def send_mail(self, subject=None, content=None, to_address=None, cc_address_list
3542
msg['From'] = self.from_address
3643
msg['To'] = to_address
3744
# print(cc_address_list)
38-
msg['Cc'] = ", ".join(cc_address_list) if cc_address_list and len(cc_address_list)>0 else None
45+
msg['Cc'] = ", ".join(cc_address_list) if cc_conditions else None
46+
msg['Reply-To'] = reply_to_addr if reply_to_addr else self.from_address
3947

4048
msg.attach(MIMEText(content))
4149

0 commit comments

Comments
 (0)