Sending Confirmation Emails with Resend

Sending Confirmation Emails with Resend

Author: Amit Jotwani, Sr. Developer Advocate II, DigitalOcean


Welcome to the final day of our?12 Days of DigitalOcean?series! We’ve come a long way, building an?Email-Based Receipt Processing Service?that extracts receipt details from?Postmark?using?DigitalOcean’s GenAI Agent, securely?stores attachments in DigitalOcean Spaces, and?saves the extracted data in Google Sheets.

Today, we’ll add the final touch—sending confirmation emails back to the sender with the receipt details, attachment links, and a link to the Google Spreadsheet. This final step ties everything together, ensuring that users get immediate feedback that their receipts have been successfully processed.

?? What You’ll Learn

By the end of this tutorial, you’ll know how to:

  1. Use the Resend API to send confirmation emails programmatically.
  2. Securely manage sensitive credentials using environment variables.
  3. Format and send transactional emails with receipt details, attachment links, and spreadsheet URLs.
  4. Test and troubleshoot a complete email processing workflow.

?? What You’ll Need

If you’d like to build along, we assume that you’ve followed?Day 11: Save Receipt Data and Attachments in Google Sheets?and already have:

If you’re just interested in learning how to integrate?Resend?for sending confirmation emails, you’ll need:

  • A Resend account: Sign up at?Resend.
  • An API key: Generate it from your Resend dashboard.

Step 1: Create a Resend Account and Get the API Key

To send emails programmatically, we’ll use?Resend, a developer-friendly API for sending transactional emails. It simplifies sending emails so you don’t have to wrestle with setting up an email server, managing SMTP configurations, or worrying about spam filters.

  1. First, go to?Resend?and sign up for a free account. Once logged in, navigate to the?API Keys?section of the dashboard and generate a new API key.

2. Give your API key a?descriptive name, like?Receipt Processor App, and set its?permission?to?Full Access.

3. Copy the API Key:?Your API key will be shown only once—copy it and keep it safe. You’ll need it in the next step to authenticate your app with Resend.

Step 2: Update Your Environment Variables

Now that we have the Resend API key, let’s save it as an environment variable in DigitalOcean, just like we’ve been doing throughout this series.

For the Resend integration, we need to save two environment variables:

  • RESEND_API_KEY: The API key you generated in Step 1, which authenticates your app with Resend.
  • RESEND_EMAIL_FROM: The sender email address you’ll use to send confirmation emails. This should be an address verified in your Resend account.

To add these variables, follow these steps:

  1. Head over to your DigitalOcean App Platform dashboard, find your Flask app, and navigate to the?Settings?tab. Under?Environment Variables, add the two variables:
  2. Save your changes to make the Resend API key available to your Flask app, which we will update next.

Step 3: Install the Resend Python Library

Next, we’ll install the Resend Python library to handle the API for us. It keeps your code clean and avoids dealing with raw HTTP requests. Run this in your terminal:

Step 4: Update?requirements.txt

Instead of editing?requirements.txt?by hand, use?pip freeze?to list all installed dependencies with exact versions. Run this:

This updates?requirements.txt?with everything your app needs, including?resend.

Step 5: Write the Function to Send Emails

Now it’s time to add the logic for sending confirmation emails. Think of it like emailing a friend to let them know their package has arrived—only here, it’s for receipts.

We’ll write a?send_confirmation_email?function that takes the recipient’s email, receipt details, attachment links, and Google Spreadsheet URL. Using Resend, it will format this into an email and send it. Here’s the function:


Step 5: Deploy to DigitalOcean

To deploy the updated Flask app, follow the steps from?Day 7: Building and Deploying the Email-Based Receipt Processor. Here’s a quick summary:

  1. Push Your Updated Code to GitHub: After making the necessary changes to your Flask app, commit and push the updated code to GitHub. This will trigger an automatic deployment in DigitalOcean’s App Platform.

2. Monitor Deployment: You can track the progress in the?Deployments?section of your app’s dashboard.

3. Verify Your Deployment: After the deployment completes, navigate to your app’s public URL and test its functionality. You can also check the?runtime logs?in the dashboard to confirm that the app started successfully.

4. Check Runtime Logs: If something isn’t working as expected, use the?Runtime Logs?tab in the App Platform dashboard to debug runtime issues. Look for any errors related to the Resend API or other app components.

Step 5: Test the Entire Workflow

Now that your app is fully configured and ready, it’s time to test the entire workflow. We’ll ensure that the?email body is processed, attachments are decoded and?uploaded to DigitalOcean Spaces, receipt details and attachment URLs are?saved in Google Sheets, and a?confirmation email is sent?to the sender.

Here’s how you can test step by step:

  1. Send a Test Email: Send an email to Postmark with a text body and an attachment. If you’re unsure how to configure Postmark, check?Day 8: Connecting Postmark to Your Flask App, where we walked through setting up Postmark to forward emails to your app.

2. Check Postmark Activity JSON: In the Postmark dashboard, navigate to the?Activity?tab. Locate the email you sent and ensure that the JSON payload includes the text body and Base64-encoded attachment data. This confirms Postmark is correctly forwarding the email data to your app, as we set up in?Day 8.

3. Monitor the Logs: Check the runtime logs in your DigitalOcean App Platform dashboard to ensure the app processes the JSON payload. You should see logs showing that receipt details were extracted and attachments were uploaded to DigitalOcean Spaces. You can access the runtime logs in the?Logs?tab of the DigitalOcean App Platform dashboard. If you’re not familiar with DigitalOcean logs, we explored this during?Day 9: Automating Receipt Parsing withDigitalOcean’s GenAI Agent.

4. Verify Spaces Upload: Visit your DigitalOcean Space to confirm that the files were uploaded successfully. You should see the attachments in your bucket as configured in?Day 10: Storing Attachments in DigitalOcean Spaces. If everything went as expected, your attachment URLs will be accessible.

5. Check Google Sheets: Open your Google Sheet and confirm that a new row with receipt details and attachment URLs has been added, as we set up on?Day 11: Saving Receipt Details in Google Sheets. The row should include:

  • Vendor, amount, currency, and date extracted from the email body.
  • Comma-separated URLs for the uploaded attachments in the last column.

6. Verify the Confirmation Email: Finally, check the inbox of the sender’s email address to ensure the confirmation email was received. This email should contain:

  • The extracted receipt details (vendor, amount, currency, and date).
  • Links to the uploaded attachments in DigitalOcean Spaces.
  • A link to the Google Spreadsheet where the receipt data is logged.

Troubleshooting

If the workflow doesn’t work as expected, here are a few troubleshooting steps to follow:

  1. Check the Resend Emails Dashboard for Errors: Visit the Resend dashboard to see if any errors occurred while sending the confirmation email.
  2. Verify Environment Variables: Make sure the API key (RESEND_API_KEY) and sender email (RESEND_EMAIL_FROM) are correctly configured in your environment variables on the DigitalOcean App Platform dashboard.
  3. Inspect DigitalOcean Runtime Logs: Open the?Runtime Logs?tab in your DigitalOcean App Platform dashboard to check for errors while processing the email or uploading attachments. These logs can provide helpful insights, especially for interactions with Postmark or Resend.
  4. Review Postmark Activity: In Postmark’s?Activity?tab, confirm that the test email was properly forwarded to your Flask app. If there are any issues, Postmark will display errors related to forwarding or configuration problems.

?? Wrap-Up

Congratulations! You’ve successfully completed the?12 Days of DigitalOcean?series and built a fully functional?Email-Based Receipt Processing Service.

Today, you:

  • Integrated the Resend API for sending transactional emails.
  • Configured environment variables to securely manage sensitive credentials.
  • Sent confirmation emails with receipt details, attachment links, and a spreadsheet URL.
  • Tested the full workflow from email submission to final confirmation.

By adding confirmation emails, you’ve wrapped up a project that processes emails, extracts details, stores attachments, and keeps everything organized in Google Sheets. It’s user-friendly, practical, and ready to solve real-world problems.

?? The 12 Days of DigitalOcean

This marks the end of the?12 Days of DigitalOcean?series. Over the past 12 days, we’ve built two real-world applications, one step at a time. Along the way, you’ve used tools like DigitalOcean’s?Serverless Functions,?App Platform,?Spaces Object Storage,?PostgreSQL,?DigitalOcean GenAI,?Twilio,?Google Sheets API,?Postmark,?PaperTrail, and?Resend. Each piece came together to form something greater than the sum of its parts.

Here’s a quick recap of what you’ve built:

?? Days 1–6: Build a Birthday Reminder Service

This app tracks birthdays and sends SMS reminders automatically. It’s lightweight, serverless, and easy to maintain.

By Day 6, you have a fully automated service running in the cloud. It just works.

?? Days 7–12: Build an Email Receipt Processor

This app handles emailed receipts, extracts the needed details, and organizes everything in a database.

By Day 12, you’ve built a complete tool that handles receipts end-to-end.

What You’ve Learned

  1. Storing and Managing Data: You used?PostgreSQL?for structured data storage and?Google Sheets?for easy, sharable data logging.
  2. Automating Workflows: With DigitalOcean?Functions?and?scheduling triggers, you automated processes and made your apps run like clockwork.
  3. Adding Intelligence to Your Apps: By integrating?DigitalOcean’s GenAI, you brought intelligent data extraction and organization into your workflows, making your apps smarter and more capable.
  4. Handling Files Securely: You worked with DigitalOcean?Spaces?to store and manage files in a reliable, scalable way.
  5. Enhancing Apps with APIs: APIs like?Twilio,?Postmark, and Resend brought functionality like SMS notifications, email forwarding, and confirmation emails to your apps.
  6. Debugging and Monitoring: Using tools like Papertrail, you learned to?debug and monitor?your apps effectively, keeping them running smoothly.

What’s next

This is just the beginning—what you’ve learned here can be applied to countless other projects. Here are a few ways to keep going:

If you follow along, I’d love to see what you create—feel free to share your progress or feedback with me on?Twitter.

Keep it simple. Build something useful. Happy building! ??


Looking for more Tutorials like this? Check out the DigitalOcean Community Page.


要查看或添加评论,请登录

DigitalOcean的更多文章

社区洞察

其他会员也浏览了