piknik icon indicating copy to clipboard operation
piknik copied to clipboard

Add multiple attachments to email message; accept Vec<SinglePart>

Open mgierada opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. It would be great if one could define a Vec<SinglePart> and attached that to Message or MessageBuilder as either a single-art or multipart elements.

Describe the solution you'd like The possible syntax for building email message

    let email = Message::builder()
        .to(TARGET_EMAIL.as_str().parse().unwrap())
        .from(FROM_EMAIL.as_str().parse().unwrap())
        .subject(SUBJECT.as_str())
        .multipart(
            MultiPart::mixed()
                .singlepart(
                    SinglePart::builder()
                        .header(ContentType::TEXT_HTML)
                        .body(String::from("text_content")),
                )
                .singlepart(attachments),
        )
        .unwrap();

where attachments is a Vec<SinglePart> which I can get by playing with

    Attachment::new(filename).body(filebody, content_type)

Describe alternatives you've considered Please, if there is a better way to programmatically assign a set of attachments to email message other then just by adding a .singlepart(...) with a single Attachment, let me know.

Additional context My use case is the following. Imagine I want to construct the method that adds n number of attachments to MessageBuilder.

mgierada avatar Jan 09 '24 21:01 mgierada