Contact Info

Atlas Cloud LLC 600 Cleveland Street Suite 348 Clearwater, FL 33755 USA

support@dedirock.com

Client Area
Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3

Welcome to the final day of our 12 Days of DigitalOcean series, where we’ve been working on building an Email-Based Receipt Processing Service. Throughout this series, we’ve taken steps to build a system that extracts details from receipts, utilizes DigitalOcean’s GenAI for processing, saves data in Google Sheets, and securely stores attachments in DigitalOcean Spaces.

Today, we are adding a vital feature: sending confirmation emails back to the users with details of their receipt processing. This step provides immediate feedback that their receipts have been processed successfully, which is crucial in enhancing user experience.

What You’ll Learn

By the end of this tutorial, you will learn how to:

  1. Use the Resend API to send confirmation emails programmatically.
  2. Manage sensitive information securely using environment variables.
  3. Format and send transactional emails with detailed receipt information and links.
  4. Test and troubleshoot a complete email processing workflow.

What You’ll Need

To follow along, you should have the following prerequisites in place:

  • A deployed Flask app for processing receipt emails.
  • Configured Google Sheets and DigitalOcean Spaces for your application.

For those focused solely on learning how to integrate Resend, ensure you have:

  • A Resend account.
  • An API key generated from your Resend dashboard.

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

To programmatically send emails, we’ll use Resend, which simplifies email configuration processes.

  1. Head to Resend and create a free account. Once you’re logged in, navigate to the API Keys section and generate a new API key.
  2. Label your API key clearly, such as "Receipt Processor App", and grant it full access.
  3. Copy the API key and keep it secure; you will use it in the following steps.

Step 2: Update Your Environment Variables

Now that we have the Resend API key, we need to secure it within our DigitalOcean environment.

  1. Navigate to your DigitalOcean App Platform dashboard and find your Flask app.
  2. In the Settings tab, under Environment Variables, add the following:
    • RESEND_API_KEY: Paste your API key here.
    • RESEND_EMAIL_FROM: Enter a verified sender email address from your Resend account.

Step 3: Install the Resend Python Library

Next, install the Resend Python library to handle API requests easily. You can install it using pip by running:

pip install resend

Step 4: Update requirements.txt

To ensure all dependencies are captured, update your requirements.txt file by running:

pip freeze > requirements.txt

Step 5: Write the Function to Send Emails

We will now implement the function that sends confirmation emails, which will include the receipt details, links to attachments, and spreadsheet URLs. Here’s the function example:

def send_confirmation_email(to_email, receipt_data, attachment_urls, spreadsheet_url):    """    Send a confirmation email with receipt details and attachment URLs.    """    email_from = os.getenv('RESEND_EMAIL_FROM')    subject = "Receipt Processed Successfully"    email_body = f"""    <h1>Receipt Confirmation</h1>    <p>Your receipt has been successfully processed. Here are the details:</p>    <ul>        <li><strong>Vendor:</strong> {receipt_data.get('vendor', 'N/A')}</li>        <li><strong>Amount:</strong> {receipt_data.get('amount', 'N/A')}</li>        <li><strong>Currency:</strong> {receipt_data.get('currency', 'N/A')}</li>        <li><strong>Date:</strong> {receipt_data.get('date', 'N/A')}</li>    </ul>    <p><strong>Attachments:</strong></p>    <ul>        {''.join(f'<li><a href="{url["url"]}">{url["file_name"]}</a></li>' for url in attachment_urls)}    </ul>    <p>You can view the processed data in the spreadsheet: <a href="{spreadsheet_url}">Google Spreadsheet</a></p>    """    try:        resend.Emails.send({            "from": email_from,            "to": to_email,            "subject": subject,            "html": email_body        })        logging.info(f"Confirmation email sent to {to_email}.")    except Exception as e:        logging.error(f"Failed to send confirmation email: {e}")

Step 6: Deploy to DigitalOcean

To deploy your updated Flask app:

  1. Push your changes to your GitHub repository.
  2. Monitor the deployment on your app dashboard.

Step 7: Test the Entire Workflow

Test the complete workflow by sending a test email to your Postmark address. Validate all components, including:

  • Successful email receipt processing.
  • Correct upload of attachments in DigitalOcean Spaces.
  • The addition of receipt details in Google Sheets.
  • Receipt of confirmation emails, ensuring they contain the necessary details.

Wrap-Up

Congratulations! You have completed the 12 Days of DigitalOcean and implemented a fully functioning Email-Based Receipt Processing Service. You have now:

  • Integrated Resend for transactional emails.
  • Configured environment variables for security.
  • Implemented a workflow that processes receipts and sends confirmations.

This project serves practical purposes and effectively demonstrates how to automate and streamline receipt management, ensuring user satisfaction through timely notifications.

As you take this experience forward, remember to explore further projects using DigitalOcean’s robust product offerings. Happy building!


Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.

Share this Post
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x