Letrre学习

Message

1
2
3
4
5
6
7
8
9
# 邮件建造示例
let email = Message::builder()
        .from("NoBody <nobody@domain.tld>".parse().unwrap())
        .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
        .to("Hei <hei@domain.tld>".parse().unwrap())
        .subject("Happy new year")
        .header(ContentType::TEXT_PLAIN)
        .body(String::from("Be happy!"))
        .unwrap();
  • from - 邮件发送人
  • to - 邮件收件人
  • reply_to - 邮件默认回复邮(发送的邮件(设置了该项),收到者点击回复邮件自动定向到设定的邮箱)
  • subject - 邮件主题
  • header - 内容形式
  • body - 邮件内容

SmtpTransport

1
2
3
4
5
// Open a remote connection to example
let mailer = SmtpTransport::from_url("smtps://username:password@smtp.example.com:465")?.build();
// Send the email
mailer.send(&email)?;
Ok(())
1
2
3
4
5
6
7
8
9
10
// Create the SMTPS transport
let sender = SmtpTransport::relay("smtp.example.com")?
// Add credentials for authentication
.credentials(Credentials::new(
"username".to_owned(),
"password".to_owned(),
))
// Optionally configure expected authentication mechanism
.authentication(vec![Mechanism::Plain])
.build();