Skip to content

Commit

Permalink
Rust: Updated send-email.rs for Contact list with more that one conta…
Browse files Browse the repository at this point in the history
…ct, SES (#5202)

* Update send-email.rs

cs is being returned without a comma. 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"}) } })

If the contact list has more that one contact it will fail.

* Update send-email.rs - Fixed for Contact List with more that one

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

* Update send-email.rs

rustfmt

---------

Co-authored-by: David Souther <davidsouther+github@gmail.com>
  • Loading branch information
d-ufrik and DavidSouther authored Sep 13, 2023
1 parent 5f70d9a commit 1b9b30a
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| 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 1b9b30a

Please sign in to comment.