...

/

Send Individual Thank You Emails

Send Individual Thank You Emails

Learn about external Ruby gems and use the email gem to send emails.

Problem

Jessica had a birthday party and received gifts from friends. She'll now send each of her friends a personalized email thanking them. Instead of sending the emails one by one, she wants a program to send emails to each of her friends by running a single command.

Her email looks like this:

Dear Angela,
Thank you for coming to my 12th birthday party,
I really like the gift you gave me: Cat Statue, thank you very much!
Jessica.
Sample content of a thank-you email

A list of people with their emails and gifts she received is given below:

first_name

email

gift

Pokkle

pokkle@example.com

Bow and arrows

Angela

catlover@example.com

Cat statue

Tonpa

tonpa@example.com

Juice machine

Toby

tobytoby123@example.com

Necklace

Biscuit

biskykruger@example.com

Blue jewel

Mito

auntiemito@example.com

Cook book

Kate

katiecat@example.com

Whale poster

Renee

renee@example.com

Camera

Chloe

chloe@example.com

Pencil case

Kelly

kellyisarabbit1@example.com

Rabbit ears

Melody

melody.456@example.com

CD

Purpose

  • Create a custom template file for substitution

  • Work with a complex data structure

  • Use external Ruby library (gem)

  • Send emails

  • Use chain of string substitution

Analyze

Custom template creation

  • This exercise requires more complex data structures and several new concepts. By examining the sample email, we see three differences among the emails to be sent:

    • Recipient’s email address (in the email header)

    • Recipient’s first name

    • The gift brought by the recipient

  • Therefore, we need to design a data structure to pass all the above data (for each person) to the template to generate one email. Think about using data structures like ...