Search code examples
rustsmtpsmtpclient

Rust Lettre send an insecure email


I have a mail server that doesn't require auth. I have been using lettre

I followed there examples and tried to specify the port to 25, without passing creds. But it still fails with a timeout connecting to server. I believe that's because relay forces tls of some kind

    let tls = TlsParameters::builder("smtp.example.com".to_string())
        .dangerous_accept_invalid_certs(true)
        .dangerous_accept_invalid_hostnames(true)
        .build()
        .unwrap();
    let mailer = SmtpTransport::relay("smtp.example.com")
    .unwrap()
    .tls(Tls::Required(tls))
    .port(25)
    .build();

It shouldn't be using tls at all, but I don't know how to turn it off.

Is that possible or do I need a different crate


Solution

  • Lettre has its own function for insecure mail servers. Use builder_dangerous. Per the docs:

    Creates a new SMTP client

    Defaults are:

    • No authentication
    • No TLS
    • A 60 seconds timeout for smtp commands
    • Port 25

    Here's an example of what it would look like

        let mailer = SmtpTransport::builder_dangerous("smtp.example.com")
            .build();
    

    Note that you can still build off of this and specify port, tls, and authentication.