From 770e321bed87c5cc55072ced45c91234c86890ab Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 1 Mar 2024 08:40:02 +0100 Subject: [PATCH] allow sending mails w/o attachments :-) --- src/model/mail.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/model/mail.rs b/src/model/mail.rs index d82b8e5..e52866e 100644 --- a/src/model/mail.rs +++ b/src/model/mail.rs @@ -52,14 +52,16 @@ impl Mail { let content = fs::read(temp_file.path().unwrap()).unwrap(); let media_type = format!("{}", temp_file.content_type().unwrap().media_type()); let content_type = ContentType::parse(&media_type).unwrap(); - let attachment = Attachment::new(format!( - "{}.{}", - temp_file.name().unwrap(), - temp_file.content_type().unwrap().extension().unwrap() - )) - .body(content, content_type); + if let Some(name) = temp_file.name() { + let attachment = Attachment::new(format!( + "{}.{}", + name, + temp_file.content_type().unwrap().extension().unwrap() + )) + .body(content, content_type); - multipart = multipart.singlepart(attachment); + multipart = multipart.singlepart(attachment); + } } let email = email.subject(data.subject).multipart(multipart).unwrap();