lettre / lettre

a mailer library for Rust
https://lettre.rs
MIT License
1.77k stars 191 forks source link

failed to lookup address information: nodename nor servname provided, or not known #575

Closed daviscai closed 3 years ago

daviscai commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

code:

use lettre::{AsyncTransport, Message, message::{header, MultiPart, SinglePart}};
use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor};

let creds = Credentials::new("smtp_username", "smtp_password");
let mailer: AsyncSmtpTransport::<Tokio1Executor> = AsyncSmtpTransport::<Tokio1Executor>::builder_dangerous("smtp.qq.com")
            .port(587)
            .credentials(creds)
            .build();

let email = Message::builder()
    .from("xxxx@xxxx.com".parse().unwrap())
    .reply_to("xxxx@xxxx.com".parse().unwrap())
    .to("xxxx@xxxx.com".parse().unwrap())
    .subject("test mail")
    .body(String::from("test rust mailer"))
    .unwrap();

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

cargo run , panick error message:

thread 'actix-rt|system:0|arbiter:1' panicked at 'Could not send email: Io(Custom { kind: Other, error: "failed to lookup address information: nodename nor servname provided, or not known" })'

Environment (please complete the following information):

Additional context Add any other context about the problem here.

mail server can telnet success

 telnet smtp.qq.com 587
Trying 183.3.225.42...
Connected to smtp.qq.com.
Escape character is '^]'.
220 newxmesmtplogicsvrszc9.qq.com XMail Esmtp QQ Mail Server.

502 Invalid input from 100.107.4.33 to newxmesmtplogicsvrszc9.qq.com
paolobarbolini commented 3 years ago

I can't reproduce the issue. I tried this both using my connection and on a VPS here in the EU and it seems to be connecting correctly to smtp.qq.com.

The error seems to indicate a DNS resolution failure, so unless something weird is going on retrying the request should fix the issue.

daviscai commented 3 years ago

this issue has been resolved.

my toml config:

[email]
server = "smtp.qq.com"
port = 587
smtp_username = ""
smtp_password = ""

and my code :

let config:Toml = toml::from_str(&file_content).unwrap();

then, toml to json , "smtp.qq.com" turned to "\"smtp.qq.com\""

thanks for your help .