Run 'cargo fmt' to format code (#489)
This commit is contained in:
committed by
Baptiste Gelez
parent
732f514da7
commit
b945d1f602
+25
-10
@@ -6,8 +6,8 @@ pub use self::mailer::*;
|
||||
|
||||
#[cfg(feature = "debug-mailer")]
|
||||
mod mailer {
|
||||
use lettre::{Transport, SendableEmail};
|
||||
use std::{io::Read};
|
||||
use lettre::{SendableEmail, Transport};
|
||||
use std::io::Read;
|
||||
|
||||
pub struct DebugTransport;
|
||||
|
||||
@@ -18,11 +18,18 @@ mod mailer {
|
||||
println!(
|
||||
"{}: from=<{}> to=<{:?}>\n{:#?}",
|
||||
email.message_id().to_string(),
|
||||
email.envelope().from().map(ToString::to_string).unwrap_or_default(),
|
||||
email
|
||||
.envelope()
|
||||
.from()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default(),
|
||||
email.envelope().to().to_vec(),
|
||||
{
|
||||
let mut message = String::new();
|
||||
email.message().read_to_string(&mut message).map_err(|_| ())?;
|
||||
email
|
||||
.message()
|
||||
.read_to_string(&mut message)
|
||||
.map_err(|_| ())?;
|
||||
message
|
||||
},
|
||||
);
|
||||
@@ -40,13 +47,12 @@ mod mailer {
|
||||
#[cfg(not(feature = "debug-mailer"))]
|
||||
mod mailer {
|
||||
use lettre::{
|
||||
SmtpTransport,
|
||||
SmtpClient,
|
||||
smtp::{
|
||||
authentication::{Credentials, Mechanism},
|
||||
extension::ClientId,
|
||||
ConnectionReuseParameters,
|
||||
},
|
||||
SmtpClient, SmtpTransport,
|
||||
};
|
||||
use std::env;
|
||||
|
||||
@@ -57,7 +63,8 @@ mod mailer {
|
||||
let helo_name = env::var("MAIL_HELO_NAME").unwrap_or_else(|_| "localhost".to_owned());
|
||||
let username = env::var("MAIL_USER").ok()?;
|
||||
let password = env::var("MAIL_PASSWORD").ok()?;
|
||||
let mail = SmtpClient::new_simple(&server).unwrap()
|
||||
let mail = SmtpClient::new_simple(&server)
|
||||
.unwrap()
|
||||
.hello_name(ClientId::Domain(helo_name))
|
||||
.credentials(Credentials::new(username, password))
|
||||
.smtp_utf8(true)
|
||||
@@ -70,9 +77,17 @@ mod mailer {
|
||||
|
||||
pub fn build_mail(dest: String, subject: String, body: String) -> Option<Email> {
|
||||
Email::builder()
|
||||
.from(env::var("MAIL_ADDRESS")
|
||||
.or_else(|_| Ok(format!("{}@{}", env::var("MAIL_USER")?, env::var("MAIL_SERVER")?)) as Result<_, env::VarError>)
|
||||
.expect("Mail server is not correctly configured"))
|
||||
.from(
|
||||
env::var("MAIL_ADDRESS")
|
||||
.or_else(|_| {
|
||||
Ok(format!(
|
||||
"{}@{}",
|
||||
env::var("MAIL_USER")?,
|
||||
env::var("MAIL_SERVER")?
|
||||
)) as Result<_, env::VarError>
|
||||
})
|
||||
.expect("Mail server is not correctly configured"),
|
||||
)
|
||||
.to(dest)
|
||||
.subject(subject)
|
||||
.text(body)
|
||||
|
||||
Reference in New Issue
Block a user