1

I try to send email from my backend using lettre to my mail server but I get the error

lettre::transport::smtp::Error { kind: Permanent(Code { severity: PermanentNegativeCompletion, category: Syntax, detail: Zero }), source: "5.5.2 Error: command not recognized" }

Postfix side

improper command pipelining after EHLO from x.x.x.x: QUIT\r\n

The following implementation comes from the examples provided here.

use lettre::{
    message::header::ContentType, transport::smtp::authentication::Credentials, Message,
    SmtpTransport, Transport,
};

fn main() {
    let email = Message::builder()
        .from("[email protected]".parse().unwrap())
        .to("[email protected]".parse().unwrap())
        .subject("Test mailer")
        .header(ContentType::TEXT_PLAIN)
        .body(String::from("Hello world !"))
        .unwrap();

    let creds = Credentials::new("smtp_username".to_owned(), "smtp_password".to_owned());

    let mailer = SmtpTransport::starttls_relay("mydomain.tld")
        .unwrap()
        .credentials(creds)
        .build();

    // Send the email
    match mailer.send(&email) {
        Ok(_) => println!("Email sent successfully!"),
        Err(e) => panic!("Could not send email: {e:?}"),
    }
}

I only have issues with this script, I have no problems with a dummy python script using smptlib or mail clients.

UPDATE : By using the internal ip of the postfix server (containerized) instead of the domain name, I get the following error. This issue only happens with lettre.

Some(lettre::transport::smtp::Error { kind: Connection, source: Failure(Ssl(Error { code: ErrorCode(1), cause: Some(Ssl(ErrorStack([Error { code: 337047686, library: "SSL routines", function: "tls_process_server_certificate", reason: "certificate verify failed", file: "ssl/statem/statem_clnt.c", line: 1919 }]))) }, X509VerifyResult { code: 64, error: "IP address mismatch" })) })

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.