Skip to content

Commit

Permalink
handle stuck issue when max limit are hit
Browse files Browse the repository at this point in the history
Signed-off-by: sinmentis <20508894+sinmentis@users.noreply.github.com>
  • Loading branch information
sinmentis committed May 8, 2024
1 parent e271a95 commit b718b89
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/MassEmailSender/MassEmailSender.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,15 @@ def _start_sending(self, server, email_list, callback):
self.email_content['To'] = Header(destination.email_address, 'utf-8')

if self.debug_only:
print(f"DEBUG_ONLY: Email Sent from {self.current_sender['username']} to {destination['email_address']}")
print(
f"DEBUG_ONLY: Email Sent from {self.current_sender['username']} to {destination.email_address}")
else:
try:
server.send_message(self.email_content)
self.current_sender["daily_send_number"] += 1
print(
f"({index + 1}/{len(self.destination_list):<5})\t{str(self.email_content['From']):<10} -> "
f"{str(self.email_content['To']):<20}")
self.num_email_sent += 1
callback(self.num_email_sent)
except:
break
server.send_message(self.email_content)
self.current_sender["daily_send_number"] += 1
print(
f"({index + 1}/{len(self.destination_list):<5})\t{str(self.email_content['From']):<10} -> {str(self.email_content['To']):<20}")
self.num_email_sent += 1
callback(self.num_email_sent)

def start_sending(self, callback=None):
email_left = self.destination_list[:]
Expand All @@ -253,14 +250,15 @@ def start_sending(self, callback=None):
server.ehlo() # re-identify ourselves as an encrypted connection

login_status = server.login(self.current_sender["username"], self.current_sender["password"])
# print(f"login_status: {login_status}" )
self._start_sending(server, email_left[:num_email_available], callback)
email_left = email_left[num_email_available:]
print(f"login_status: {login_status}")
number_to_send = min(len(email_left), num_email_available)
self._start_sending(server, email_left[:number_to_send], callback)
email_left = email_left[number_to_send:]
except Exception as e:
print(f"error: {e}")
print(f"Send err: {e}")
if not self._switch_next_available_sender():
return
return False
else:
if not self._switch_next_available_sender():
return False
return True
return True

0 comments on commit b718b89

Please sign in to comment.