Parse multiple input based on jsonfile with lettre

Hi all this is my first topic on this forum as beginner in programming and specially rust. After reading the book and following the rustlings examples, I started to make my first little program.

I will try to formulate my question as accurately as possible.

I want to send an email to multiple receivers, with a variable content as body. I made the following code with the lettre crate, and it works fine if i want to send it to 1 user:

extern crate chrono;
extern crate lettre;
extern crate json_macros;

use std::io;
use std::io::prelude::*;
use chrono::prelude::*;
use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};

fn main() {

        // Must be send to following adresses, based on json file/format
        let to_adresses = json!({
            "To Reciever 1": "",
            "To Reciever 2": "",

        let dw_subject = format!("Message send on {}", Local::now().format("%A %e %B %Y"));
        let dw_body = format!("{}", someinput);
        let email = Message::builder()
            .from("From Sender <>".parse().unwrap())
            .to("To Reciever 1<>".parse().unwrap())

        let creds = Credentials::new(

        // Open a remote connection to gmail
        let mailer = SmtpTransport::relay("")

        // Send the email
        match mailer.send(&email) {
            Ok(_) => println!("mail send!"),
            Err(e) => panic!("Mail not send because: {:?}", e),

I did try to use a vector and a for loop with no success.(I also think not optimal because the code has to generate message :: builder several times)
Need some advice how to implement this.

First, welcome to Rust and to this forum. You will find many people on this forum who are willing to help.

Second, please edit your Rust code in the above post so that if follows the Forum Code Formatting and Syntax Highlighting guidelines, which are pinned to the top of this forum so that all new posters will see them. You can edit any of your own posts by clicking on the pencil-shaped "edit this post" button under your posts to apply correct formatting.

Most readers of this forum view with distaste code snippets that do not follow those posting guidelines. Not following the guidelines disrespects all forum readers, including those whom you are asking for advice. Thanks. :clap:


Can't figure it out yet. :thinking:

lettre has an struct Mailboxes it seems it can handle multiple username and email adresses as a vector.

I tried multiple ways to implement this but I still cant figure it out. :flushed: feeling little bit stupid...

can someone give me a hint/directions?

I solved it with multiple .to argements

let email = Message::builder()
            .from("From Sender <>".parse().unwrap())
            .to("To Reciever 1<>".parse().unwrap())
            .to("To Reciever 2<>".parse().unwrap())

Not a clean solution but it works fine for know :flushed:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.