forked from chatmail/async-smtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmtp_gmail.rs
39 lines (33 loc) · 1.14 KB
/
smtp_gmail.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use async_smtp::smtp::authentication::Credentials;
use async_smtp::{EmailAddress, Envelope, SendableEmail, SmtpClient};
fn main() {
async_std::task::block_on(async move {
let email = SendableEmail::new(
Envelope::new(
Some(EmailAddress::new("[email protected]".to_string()).unwrap()),
vec![EmailAddress::new("[email protected]".to_string()).unwrap()],
)
.unwrap(),
"id".to_string(),
"Hello example".to_string().into_bytes(),
);
let creds = Credentials::new(
"example_username".to_string(),
"example_password".to_string(),
);
// Open a remote connection to gmail
let mut mailer = SmtpClient::new("smtp.gmail.com")
.await
.unwrap()
.credentials(creds)
.into_transport();
// Send the email
let result = mailer.connect_and_send(email).await;
if result.is_ok() {
println!("Email sent");
} else {
println!("Could not send email: {:?}", result);
}
assert!(result.is_ok());
});
}