5. Sending the Email
Now we’re ready for the final step. We’re going to take each of those story responses and collate them into an email body and then send it off to our recipient.
Service Request: send_email
send_email
Navigate to the Build page, go to the Service Requests for our integration, and add a new row. Enter the following values:
Sequence:
200
System:
EMAIL_SMTP
Service Name:
n/a
Formula Variable:
send_email
Before Prepare Request Hook: copy and paste the code below. This is the most complicated Python code we have shown to the reader thus far. Basically, we are creating a standard message for each story we received, and writing it to a file. We will later read this file for the body of the email.
Field Mappings for SR: send_email
send_email
Right-click the newly-created SR and go to Field Mappings. Add 4 rows with these values and then save.
First row
Field:
from_address
Value:
"email@address.net"
(use the same email as was entered for the Email SMTP Adapter Config, and don’t forget the quotes)Value Type:
str
Second row
Field:
to_addresses
Value:
[input.payload.email]
Value Type:
list
Third row
Field:
subject
Value:
"Top HackerNews Stories"
Value Type:
str
Fourth row
Field:
body
Value:
open_glyuefile("email_body.txt").read()
Value Type:
str
Don’t forget to save!
Last updated