E-mails to organisation are now non-HTML. Fixes #2

This commit is contained in:
Dennis Potter 2019-09-05 00:33:47 +02:00
parent 29666541bc
commit 75c9473ca9
Signed by: Dennis
GPG Key ID: 186A8AD440942BAF

View File

@ -122,7 +122,9 @@ fn strip_tld(url: &str) -> Option<String> {
fn send_email(to_name: &String, to_address: &String,
subject: &String, message: &String,
attachment: Option<&String>, settings: &State<Settings>) -> Result<(), String> {
attachment: Option<&String>,
html: bool,
settings: &State<Settings>) -> Result<(), String> {
// Load HJSON config
let email_credentials = &settings.email_credentials;
@ -132,29 +134,32 @@ fn send_email(to_name: &String, to_address: &String,
let smtp_username = email_credentials.smtp_username.to_string();
let smtp_password = email_credentials.smtp_password.to_string();
// Create base object for email
let mut email = Email::builder()
.to((to_address, to_name))
.from((&smtp_username, &smtp_name))
.subject(subject);
// Check if HTML bool is set
if html {
email = email.html(message)
} else {
email = email.text(message)
}
// If an attachment is defined, send it.
let email = match attachment {
Some(x) => {
Email::builder()
.to((to_address, to_name))
.from((&smtp_username, &smtp_name))
.subject(subject)
.html(message)
.attachment_from_file(Path::new(x), None, &TEXT_PLAIN)
.unwrap()
.build()
email.attachment_from_file(Path::new(x), None, &TEXT_PLAIN)
.unwrap()
},
None => {
Email::builder()
.to((to_address, to_name))
.from((&smtp_username, &smtp_name))
.subject(subject)
.html(message)
.build()
.unwrap()
email
}
};
// Build email
let email = email.build().unwrap();
// Connect to a remote server on a custom port
let mut mailer = SmtpClient::new_simple(&smtp_server).unwrap()
@ -236,7 +241,8 @@ fn submit_task (host: HostHeader,
&x.email,
&language_strings.attending_email.subject,
&strfmt(&language_strings.attending_email.message, &vars).unwrap(),
Some(&language_strings.attending_email.attachment),
Some(&language_strings.attending_email.attachment), //attachment
true, // HTML email
&settings);
} else {
// Send email about not attending wedding
@ -244,7 +250,8 @@ fn submit_task (host: HostHeader,
&x.email,
&language_strings.not_attending_email.subject,
&strfmt(&language_strings.not_attending_email.message, &vars).unwrap(),
None,
None, // No attachment
true, // HTML email
&settings);
}
} else {
@ -261,11 +268,11 @@ fn submit_task (host: HostHeader,
rsvp_message.push_str("Name: ");
rsvp_message.push_str(&x.name);
rsvp_message.push_str("<br />Emailaddress: ");
rsvp_message.push_str("\nEmailaddress: ");
rsvp_message.push_str(&x.email);
rsvp_message.push_str("<br />Guests: ");
rsvp_message.push_str("\nGuests: ");
rsvp_message.push_str(&x.guests.to_string());
rsvp_message.push_str("<br />Message:<br /><br />");
rsvp_message.push_str("\nMessage:\n\n");
rsvp_message.push_str(&x.message);
// Create subject and add error message (if necessary)
@ -278,7 +285,7 @@ fn submit_task (host: HostHeader,
},
Err(e) => {
rsvp_subject.push_str(" just responded to your event! (ERROR)");
rsvp_message.push_str("<br />Error message:<br />");
rsvp_message.push_str("\n\nError message:\n");
rsvp_message.push_str(&e);
error = true;
}
@ -289,7 +296,8 @@ fn submit_task (host: HostHeader,
&smtp_username,
&rsvp_subject,
&rsvp_message,
None,
None, // no attachment
false, // no HTML
&settings) {
Ok(_x) => {},
Err(_e) => {