Hi,
I need to send an email from a rust program. while I was googling to see available solutions I found Lettre crate. I took the sample program provided in that page :
use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};
fn main()
{
let email = Message::builder()
.from("Here I wrote the email address of the sender".parse().unwrap())
.to("Here I wrote the email address of the destination".parse().unwrap())
.subject("Happy new year")
.body(String::from("Be happy!"))
.unwrap();
let creds = Credentials::new(
"Once again, here I wrote the email address of the sender".to_string(),
"And here I wrote the password of the sender's email account".to_string()
);
// Open a remote connection to gmail
let mailer = SmtpTransport::relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.build();
// Send the email
match mailer.send(&email) {
Ok(_) => println!("Email sent successfully!"),
Err(e) => panic!("Could not send email: {:?}", e),
}
}
The program compiled properly by downloading all dependencies specified in Cargo.toml. However when I run the program it panicked with the following error message :
thread 'main' panicked at 'Could not send email: lettre::transport::smtp::Error { kind: Connection, source: Os { code: 101, kind: NetworkUnreachable, message: "Network is unreachable" } }', src/main.rs:28:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The computer on which I run the program is inside a network protected by a proxy and I think that could explain the error message. In my Python programs for example, whenever I use Requests module to send HTTP queries to our RESTful APIs, indeed I need to specify the proxy in our network as a parameter of my query, otherwise the query will not pass. Therefore, I checked the documentation of lettre::SmtpTransport but I didn't find anything related to proxy.
So, I would like to know whether it is possible to use this crate to send email from a computer behind a proxy.
Thanks in advance