For Advanced

Lesson 5/10

What’s Your Message?

Okay, you got new emails retrieved from your inbox and stored in a variable. But you want something more than just their subjects. No worries: every ♥element inside the ♥list variable from the previous lesson’s code is a complete email message. Imagine these elements as storage boxes with a couple of drawers, where each drawer is meant for a particular mail message property. So, it’s just a matter of reaching out for a right drawer to get what you want from your email.

In fact, there are 11 “drawers” — or fields — in each email element: id, from, to, cc, bcc, subject, content, date, priority, attachments, isreply. Their names are pretty much self-explanatory, but if you need details, just refer to the mail structure description.

You can use these names as indexes to pick a desired email property, for example ♥element⟦from⟧ will get the email sender’s name, ♥element⟦content⟧ will read the message body. Change one line in the script from the previous lesson and see the results:

♥login = enter your Gmail login here
♥password = enter your Gmail password here

mail.imap login ♥login password ♥password sincedate ♥date onlyunreadmessages true ignorecertificateerrors true result ♥list 

foreach ♥element in ♥list
  dialog ♥element⟦content⟧

Feel free to experiment with other indexes.

As you can see, your Gmail credentials are in plain text in the code. It’s not the best idea to reveal such information, so in the next lesson you will learn how to avoid this by using a secure credential storage space.