Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post-office raise 2 same error when there are SMTP connection error #439

Open
elineda opened this issue Mar 22, 2023 · 1 comment
Open

Comments

@elineda
Copy link
Contributor

elineda commented Mar 22, 2023

Hello,

When I send email with post office, in case of connection error, two attempts are done, and two same errors are raised.
This is confusing because we can think post office try so send email twice (and it's not the case).

I found the code where is done, and I don't understand why it's done like that.

post_office/mail.py:257

 def send(email):
    try:
        email. Dispatch(log_level=log_level, commit=False,
                       disconnect_after_delivery=False)
        sent_emails.append(email)
        logger.debug('Successfully sent email #%d' % email.id)
    except Exception as e:
        logger.exception('Failed to send email #%d' % email.id)
        failed_emails.append((email, e))

  # Prepare emails before we send these to threads for sending
  # So we don't need to access the DB from within threads
  for email in emails:
      # Sometimes this can fail, for example when trying to render
      # email from a faulty Django template
      try:
          email.prepare_email_message()
      except Exception as e:
          logger.exception('Failed to prepare email #%d' % email.id)
          failed_emails.append((email, e))

  number_of_threads = min(get_threads_per_process(), email_count)
  pool = ThreadPool(number_of_threads)

  pool. Map(send, emails) 

Why we try so send mail which raise exception on the preparation? Should we pop them of the email array or create an array "email_prepared" to give to the send function?

@selwin
Copy link
Collaborator

selwin commented May 16, 2023

Yeah, we shouldn't attempt to connect during preparation. It would be great if you can open a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants