Lettre Crate won't work on Server

So I've been using the lettre crate to send email verification codes for account creation: https://crates.io/crates/lettre

This has been working perfectly fine in localhost (sends out emails) however when I try to send an email with my VPS it just times out. I thought it had something to do with the firewall so I enabled port 25 and 2525, but it still times out and doesn't send any emails.

Any ideas?
Thanks in advance.

This is my code:

use lettre_email::Email;
use lettre::smtp::authentication::Credentials;
use lettre::{SmtpClient, Transport};

pub fn mail(address:String, message:String)
{
    let creds = Credentials::new
    (
        "email".to_string(),
        "password".to_string(),
    );

    let mut mailer = SmtpClient::new_simple("smtp.gmail.com")
        .unwrap()
        .credentials(creds)
        .transport();

    let email = Email::builder()
        .to(address)
        .from("email")
        .subject("Verification Code")
        .text(message)
        .build()
        .unwrap();

    mailer.send(email.into()).ok();
}

What transport do you use? If it's SendmailTransport, do sendmail work if invoked directly from shell?

Not sure how to invoke sendmail through shell, but I uploaded some code if that helps.

According to documentation from Google, that's ports 465 and 587 which are used, not 25 or 2525.

I also tried it with 465 and 587 but I just disabled the firewall entirely to see if that was the problem and it still times out. The documentation in lettre mentions that for testing it requires an open mail server listening locally on port 2525; is an open mail server something that most computers have by default and perhaps the VPS is simply missing it?

Well, does the exact same code - not with local server, but with gmail - work on localhost?

I think I found the issue. Apparently linode blocks the necessary ports in their efforts to prevent spam and I need to submit a ticket for this. Running a Mail Server | Linode

Linode just lifted the restrictions. Now it no longer times out, but the email is still not sent. Do you need to set up a email server in a VPS?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.