提问人:alphaprogramming 提问时间:10/24/2023 更新时间:10/24/2023 访问量:39
Rust lettre 将电子邮件正文作为编码的 html 发送
Rust lettre send email body as an encoded html
问:
我想发送一个 base64 编码的 html,其中 lettre 作为我的电子邮件正文,这应该是可能的,但是当我在电子邮件正文中发送它时,我看到的是 onlt base64 字符串而不是我的 html 从理论上讲,如果我传递标头 content-transfer-encoding base63,它应该会自动呈现 base64,但对我来说它不起作用,这是我的代码:
let email = Message::builder()
.from(row.mail_from.parse()?)
.to(row.mail_to.parse()?)
.subject(row.mail_subject)
.header(ContentType::TEXT_HTML)
.header(ContentTransferEncoding::Base64)
.body(row.mail_body)?;
let creds = Credentials::new(smtp2go_username.to_owned(), smtp2go_password.to_owned());
let mailer = SmtpTransport::relay(&smtp2go_server)
?
.credentials(creds)
.build();
let result = mailer.send(&email);
match result {
Ok(_) => {
info!("Email sent successfully to {} with from {}", row.mail_to, row.mail_from);
// set the mail to sent
let query = format!("UPDATE notifications_mail_queue SET mail_sent = 1 WHERE id = {}", row.id);
conn.query_drop(query)?;
// set the sent date
let current_date = Local::now().to_rfc3339();
let query = format!("UPDATE notifications_mail_queue SET mail_sent_date = '{}' WHERE id = {}", current_date, row.id);
conn.query_drop(query)?;
}
Err(e) => {
error!("Failed to send email to {} with from {}. Sending with {}: {:?}", row.mail_to, row.mail_from, smtp_username, e);
}
}
答: 暂无答案
评论