Glyue User Docs
  • What is Glyue?
  • Tutorials
    • Start Here
    • Building a Single-Step Integration
      • 1. Creating the Integration
      • 2. Calling the External System
      • 3. Running the Integration
      • 4. Crafting the Output
    • Building a Multi-System Integration
      • 1. Connecting to the Core
      • 2. Field Mapping
      • 3. Running the Integration
    • Building an Event-Driven Integration
      • 1. Setting up the Mock CRM
      • 2. Receiving Inbound Requests
      • 3. Triggering the Integration from the CRM
    • Building an Email Integration
      • 1. Create and Configure the Integration
      • 2. Input Validation
      • 3. Get Story IDs from Hacker News
      • 4. Get Story Content
      • 5. Sending the Email
      • 6. Wrapping Up
      • 7. Extra credit
        • extra_credit.json
    • Building a RESTful CRUD Web Service
      • 1. Integration Setup
      • 2. Vault Setup
      • 3. Create Web Service Endpoints
      • 4. Execute Web Service Endpoints with Vault Methods
      • 5. Vault Code Examples and Explanation
    • Building a Retrieval API against FIS CodeConnect
      • 1. Integration Setup
      • 2. Service Request Setup
      • 3. Field Mapping Setup
      • 4. Integration and Service Request Hook Setup
      • 5. Testing the Integration
      • 6. Common Errors
    • What is Pre-Mapping?
      • Before you start
      • Bookmarks
      • Source and Targets
      • Field Mapping Status
      • Field Mapping Comments
      • Summary
  • How-To Guides
    • How to Run an Integration from Glyue
    • How to Invite New Users
    • How to Create a Value Mapping Set
    • How to Build and Deploy a Custom Frontend
    • How to Migrate an Integration
    • How to Set Up Single Sign On (SSO)
      • Glyue Setup
      • JumpCloud Setup
      • Azure Setup
      • Okta Setup
      • Glyue SAML Config Reference
    • How to Install the Glyue App for Zoom Contact Center
    • How to use the Vault
  • Reference
    • Integration Builder Page
    • Integration Anatomy
    • Integration Components
      • Integration
      • Service Request
      • Field Mapping
      • Value Mapping Set
      • Value Mapping
      • Validation Rule
      • Mask
      • Integration Config
      • Integration Engine Versions
    • Integration Lifecycle
    • Special Functions
      • add_run_label
      • callint
      • debug
      • end
      • get_namespace
      • humanize
      • import_helper
      • keep
      • list_files
      • map_value
      • open_glyuefile
      • open_vault
      • Data Manipulation Utilities
      • calladapter
    • Special Variables
      • __adapter_config__
      • input
      • parentint
      • retvalue
      • run_history_id
      • Iterables
        • fitem/fidx
        • sritem/sridx
        • vritem/vridx/vrmsg
    • Adapters
      • Generic HTTP Adapter
      • Email SMTP Adapter
    • Web Service Endpoints
    • Vault Reference
  • Glyue Platform Reference
    • Banking Core Connectivity Guide
    • Authentication
    • Permissions
      • Service Accounts
      • Organizations
    • Frontends
    • Idempotency Layer
    • Integration Scheduler
    • Governance Reports
    • Arbitrary Integration Request Content Support
    • Admin Components
    • Logging
  • ETL
    • Glyue ETL Overview
    • Data Connectors
    • Workflows
    • Run History
    • Scheduler
Powered by GitBook
On this page

Was this helpful?

  1. Tutorials
  2. Building an Email Integration

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

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.

    from datetime import datetime
    
    stories = [sr.response.payload for sr in get_story_by_id]
    stories.sort(key=lambda story: story.score, reverse=True)
    
    query_ct = 500 if not input.payload.limitQuery else input.payload.limitQuery
    email_limit = 50 if not input.payload.limitEmail else input.payload.limitEmail
    
    with open_glyuefile("email_body.txt", "w") as file:
        file.write(f"Here are the top {email_limit} of the latest {query_ct} articles from Hacker news:\n\n")
        for story in stories[:email_limit]:
            time = datetime.fromtimestamp(story.time).strftime("%m/%d/%Y, %H:%M")
            file.writelines([
                f"{story.title}\n",
                f"{story.url}\n",
                f"Posted by [{story.by}] on {time} ({story.score} points, {story.descendants} comments)\n",
                f"Discussion: https://news.ycombinator.com/item?id={story.id}\n\n"
            ])

Field Mappings for SR: 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!

Previous4. Get Story ContentNext6. Wrapping Up

Last updated 1 year ago

Was this helpful?