Hi, I have a paid account and running into an issue when trying to send bunch of emails (116ish). I’m not sure where is the problem, I’ve tried logging failures from today’s task but don’t see any. Some people however still reported not getting email.
Spam filters do not register any blocked emails that we initially thought are happening, and on last Friday, August 21st, 20:00 UTC where emails go out, no one seem to have got any emails. (Unfortunately I can’t seem to access log of that day since I have limited history - also discovered a leftover task that cluttered logs and since have stopped it).
I wrapped the anvil.email.send
in try/except TimoutError
since I used to see some timeouts, and I try sending each email up to 10 times.
Here is the code that I’m using, sure I can add more try/excepts but is there anything that sticks out as a culprit?
@anvil.server.background_task
@anvil.server.callable
def send_announcement():
"""
To be sent Friday at noon.
"""
announcement = "It's that time of the week to fill out the time tracker.<br>\
<br>\
Thank you!<br><br>\
{}".format(survey_link)
send_emails(email_list=all_emails, html=announcement)
def send_emails(email_list=[], html='', subject=""):
for email in email_list:
send_email(email, html, subject)
@anvil.server.callable
def send_email(email, html, subject=""):
"""
Due to timeout error I try to send email 10 times.
"""
N = 10
not_sent = True
count = 1
while not_sent and count <= N :
try:
first_name = email.split('@')[0].split('.')[0].capitalize()
anvil.email.send(to=email,
from_name="BLI Time Tracker",
subject=subject if subject else "BLI Time Tracker for {}".format(first_name),
html=html)
print('Sent email to {}'.format(email))
time.sleep(0.1)
not_sent = False
except TimeoutError:
print('Timeout: Failed to send an email to: {} ({}/{})'.format(email, count, N))
count += 1
if not_sent:
print('Skipped sending email to: {}'.format(email))