Skip to content

Commit

Permalink
Update send-email.rs - Fixed for Contact List with more that one
Browse files Browse the repository at this point in the history
Fixed.
cs is being generated as String, if the Contact list has more that one contact it will fail. eg:
user@example.comuser2@example.com...
Causes Exception:
Error: BadRequestException(BadRequestException { message: Some("Illegal address"), meta: ErrorMetadata { code: Some("BadRequestException"), message: Some("Illegal address"), extras: Some({"aws_request_id": "da0bf20a-52b3-4acc-bb22-eec27cf68322"}) } })

cs is now a Vec<String> and is directly assigned to dest.to_addresses
  • Loading branch information
d-ufrik authored and DavidSouther committed Sep 13, 2023
1 parent 6fd1dee commit c90dacc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rust_dev_preview/examples/ses/src/bin/send-email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ async fn send_message(

let contacts = resp.contacts().unwrap_or_default();

let cs: String = contacts
let cs: Vec<String> = contacts
.iter()
.map(|i| format!("{},",i.email_address().unwrap_or_default()))
.map(|i| i.email_address().unwrap_or_default().to_string() )
.collect();

let dest = Destination::builder().to_addresses(cs).build();
let mut dest: Destination = Destination::builder().build();
dest.to_addresses = Some(cs);
let subject_content = Content::builder().data(subject).charset("UTF-8").build();
let body_content = Content::builder().data(message).charset("UTF-8").build();
let body = Body::builder().text(body_content).build();
Expand Down

0 comments on commit c90dacc

Please sign in to comment.