Skip to content

Commit 7a4e5ab

Browse files
committed
Added verbosity to SMTP send
1 parent e0f6983 commit 7a4e5ab

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

email/1.3.0/src/app.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ def send_email_shuffle(self, apikey, recipients, subject, body):
7474
headers = {"Authorization": "Bearer %s" % apikey}
7575
return requests.post(url, headers=headers, json=data).text
7676

77-
def send_email_smtp(
78-
self, smtp_host, recipient, subject, body, smtp_port, attachments="", username="", password="", ssl_verify="True", body_type="html", cc_emails=""
79-
):
77+
def send_email_smtp(self, smtp_host, recipient, subject, body, smtp_port, attachments="", username="", password="", ssl_verify="True", body_type="html", cc_emails=""):
78+
self.logger.info("Sending email to %s with subject %s" % (recipient, subject))
8079
if type(smtp_port) == str:
8180
try:
8281
smtp_port = int(smtp_port)
8382
except ValueError:
8483
return "SMTP port needs to be a number (Current: %s)" % smtp_port
8584

85+
self.logger.info("Pre SMTP setup")
8686
try:
8787
s = smtplib.SMTP(host=smtp_host, port=smtp_port)
8888
except socket.gaierror as e:
@@ -95,6 +95,7 @@ def send_email_smtp(
9595
else:
9696
s.starttls()
9797

98+
self.logger.info("Pre SMTP auth")
9899
if len(username) > 1 or len(password) > 1:
99100
try:
100101
s.login(username, password)
@@ -108,6 +109,7 @@ def send_email_smtp(
108109
body_type = "html"
109110

110111
# setup the parameters of the message
112+
self.logger.info("Pre mime multipart")
111113
msg = MIMEMultipart()
112114
msg["From"] = username
113115
msg["To"] = recipient
@@ -116,10 +118,12 @@ def send_email_smtp(
116118
if cc_emails != None and len(cc_emails) > 0:
117119
msg["Cc"] = cc_emails
118120

121+
self.logger.info("Pre mime check")
119122
msg.attach(MIMEText(body, body_type))
120123

121124
# Read the attachments
122125
attachment_count = 0
126+
self.logger.info("Pre attachments")
123127
try:
124128
if attachments != None and len(attachments) > 0:
125129
print("Got attachments: %s" % attachments)
@@ -153,7 +157,7 @@ def send_email_smtp(
153157
except Exception as e:
154158
self.logger.info(f"Error in attachment parsing for email: {e}")
155159

156-
160+
self.logger.info("Pre send msg")
157161
try:
158162
s.send_message(msg)
159163
except smtplib.SMTPDataError as e:

0 commit comments

Comments
 (0)