Skip to content

Add more logging around email sending #4597

@carols10cents

Description

@carols10cents

Recently, we got some reports of email verification emails not arriving. We looked in mailgun for error reports, but there weren't any logs associated with the email addresses in mailgun's logs, so it seemed like the emails didn't even get to mailgun.

We didn't have any errors in our logs, so we didn't really have much more visibility into any potential problems.

To help debug future problems around email sending, it would be nice if we had logging of:

  • Successful email send request, including the mailgun ID
  • Failure of email send request, including any error messages

Email sending is around here:

crates.io/src/email.rs

Lines 104 to 115 in dd9893b

EmailBackend::Smtp {
server,
login,
password,
} => {
SmtpTransport::relay(server)?
.credentials(Credentials::new(login.clone(), password.clone()))
.authentication(vec![Mechanism::Plain])
.build()
.send(&email)
.map_err(|_| server_error("Error in sending email"))?;
}

I'm not sure what lettre exposes or what mailgun responds with.

This is related to #4596, in that in production the email backend should always be Smtp, so perhaps the Env enum can be used in the sending code as well to ensure this.

cc @rust-lang/crates-io-on-call, this would be super helpful for production support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-backend ⚙️C-internal 🔧Category: Nonessential work that would make the codebase more consistent or clear

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions