Merge pull request 'allow sending mails w/o attachments :-)' (#218) from staging into main
Some checks failed
CI/CD Pipeline / test (push) Failing after 12m11s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

Reviewed-on: #218
This commit is contained in:
philipp 2024-03-01 08:41:12 +01:00
commit 966254807c

View File

@ -52,15 +52,17 @@ impl Mail {
let content = fs::read(temp_file.path().unwrap()).unwrap(); let content = fs::read(temp_file.path().unwrap()).unwrap();
let media_type = format!("{}", temp_file.content_type().unwrap().media_type()); let media_type = format!("{}", temp_file.content_type().unwrap().media_type());
let content_type = ContentType::parse(&media_type).unwrap(); let content_type = ContentType::parse(&media_type).unwrap();
if let Some(name) = temp_file.name() {
let attachment = Attachment::new(format!( let attachment = Attachment::new(format!(
"{}.{}", "{}.{}",
temp_file.name().unwrap(), name,
temp_file.content_type().unwrap().extension().unwrap() temp_file.content_type().unwrap().extension().unwrap()
)) ))
.body(content, content_type); .body(content, content_type);
multipart = multipart.singlepart(attachment); multipart = multipart.singlepart(attachment);
} }
}
let email = email.subject(data.subject).multipart(multipart).unwrap(); let email = email.subject(data.subject).multipart(multipart).unwrap();