Trouble with the lettre crate

Hello rustaceans, recently I was working on a project using the lettre crate (https://crates.io/crates/lettre). After my code would take user input and process it, my function sendmail() would send the results to a certain email. The program seems to run correctly, however the email never arrives at the specified inbox. would someone please help me with the code?

extern crate lettre;

extern crate env_logger;

use lettre::{EmailAddress, Envelope, SendableEmail, Transport};

use lettre::SendmailTransport;
fn main() {

    sendmail("test message".to_string());
}

fn sendmail(message: String) {
    let envelope = Envelope::new(
        Some(EmailAddress::new("xxxxxxxx@gmail.com".to_string()).unwrap()),
        vec![EmailAddress::new("xxxxxxxxxx@gmail.com".to_string()).unwrap()]
    ).unwrap();

    let email = SendableEmail::new(
        envelope,
        "test".to_string(),
        message.as_bytes().to_vec()
    );

    let mut sender = SendmailTransport::new();
    sender.send(email);
}

Could you check your sendmail's logs? Maybe GMail is blocking you as spam, for example.

here are the sendmail logs. (using sendmail on mac)

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
344C815EAB68      305 Fri Dec 13 20:38:21  xxx@gmail.com
   (connect to alt2.aspmx.l.google.com[xxx.xxx.xx]:25: Operation timed out)
                                     xxxxx@gmail.com

30E6A15EAAA6      305 Fri Dec 13 20:37:03  xxxxxxxxx@gmail.com
      (connect to mxi.vivaldi.net[xxx.xxx.xx]:25: Operation timed out)
                                     xxxxx@vivaldi.net

Apperently the operations are timing out.

Any suggestions?

Ask a real smtp server to send the email for you. Sending email correctly is nigh-impossible and requires all sorts of crazy setup at both the server and dns level.

AFAIK that's exactly what SendmailTransport does - it simply calls the system sendmail. Or do you mean "use some external server, not your own"?

If you can set up your local sendmail correctly, go ahead, but doing that is very difficult, so I recommend using an external one you know works.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.