Facebook Twitter Instagram
    Wednesday, June 29
    Trending
    • ‘Stranger Things 4’ Creel House is a big ol’ horror homage
    • Cheaper Samsung foldables could be a thing in the next 1-2 years – Phandroid
    • Why Do Hybrids Get Great City Gas Mileage?
    • How This Amazing Campaign Succeeded in Changing a Brand’s Perception and People’s Lives at the Same Time
    • NFT and Digital Asset Authentication Technology Launches on KuCoin June 30th
    • Best Caribbean cruise tips to help you make the most of your time aboard and ashore
    • Looking for a Getaway Near Los Angeles? Try Ojai.
    • Fashion School Diaries: The Regent’s University London Graduate Inspired by Hugs and ‘Unclecore’
    Facebook Twitter Instagram Pinterest VKontakte
    Swave Digest
    • Home
    • World News
    • Technology
      • Smartphones
      • Computers
      • Programming
      • Automobiles
    • Entertainment
      • Music
      • Anime
      • Movies
    • Sports
      • Football
      • Basketball
      • Tennis
    • Business
      • Crypto
      • Stocks
      • NFT
    • Lifestyle
      • Fashion
      • Health
      • Travel
    • Shop
    Swave Digest
    Home»Technology»Programming»Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022
    Programming

    Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022

    Swave DigestBy Swave DigestJune 23, 2022No Comments7 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Stem the email marketing tide using masking

    Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022 4415 829434Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022 4415
    Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022
    Image by Anne-Onyme from Pixabay

    This story presents a proof-of-concept that allow me to give a unique email address anything@mydomain.com when subscribing to mailing lists, and registering unimportant accounts. anything can be any word that I decide on the spot when I give the address. The emails are forwarded to my normal email address — and if I find that I am receiving too many, I can unsubscribe and blacklist the address…

    As an added benefit, I am now using a different password and email address when registering on websites… That should keep me safer.

    The views/opinions expressed in this story are my own. This story relates to my personal experience and choices and is provided in the hope that it will be useful but without any warranty.

    I like to subscribe to news, forums, etc. But, I have been pwned… and I do not read most emails — just casually scan through subjects to see if anything spike my interest… I can unsubscribe, but I have the impression that these emails just keep on coming. I recently started to use a brand new email address — that I would like to keep clean and hence have been looking for a way to control who I give this email address to.

    A hacker news post [1] got me onto email masking. Google led me to the AWS blog post (Forward Incoming Email to an External Destination [2]) and this implementation.

    AWS Infrastructure Diagram

    The diagram below shows the AWS infrastructure used in the implementation of the email masking service — namely, receiving and storing the email, checking the address and forwarding it if appropriate.

    Implement an Email Masking Proof-of-concept Using AWS Simple Email Service (SES) and AWS Rust SDK | by Julien de Charentenay | Jun, 2022 1*XL2lOrezpKuUDbaZ3V9DGg
    AWS Infrastructure diagram

    The AWS infrastructure consists of:

    • A route53 record to direct incoming mail to the SES service;
    • SES rules that handle incoming emails to [email protected]save them to S3 and invoke a lambda function;
    • A lambda function that processes the incoming email, and forwards it to my normal email [email protected] if the incoming email address [email protected] is not blacklisted.

    I personally use terraform to manage the AWS infrastructure, but one can create it via the console easily — it is the same infrastructure as described in [2] — or using any other Infrastructure-as-Code tool.

    The main elements of the terraform script read as follows:

    • SES rule: The following script sets a SES rule that handles any incoming email with an address @mydomain.com. The rule has 2 actions. The first action save the email to an S3 bucket aws_s3_bucket.x.id — this bucket is created using an aws_s3_bucket resource and, importantly, a policy is applied to that bucket that allows write, aka PutObject action, from SES. The second action triggers the lambda function aws_lambda_function.x.arn. The rule is assigned to the rule set aws_ses_receipt_rule_set.mail.id that is defined using an aws_ses_receipt_rule_set resource.
    • Lambda function: The lambda function is defined with a provided runtime — ie the function is a self contained executable with no dependencies as described in [3]. The maximum memory usage is set 128MB and a runtime of 5s that has proved sufficient for my use. The function is initialized with an empty zip file as I deploy the executable using the AWS command line interface.

    To allow the SES rule and lambda to work, permissions need to be setup:

    • A resource is defined that allows the SES service to call the lambda function — I attempted to nominate the SES caller using the source arn entries, but was unable to this approach led to a circular reference.
    • Define the role used by the lambda function with a policy that allows it to read from the S3 bucket and send emails usingthe AWS SES service. The role also allows the lambda function to write logs — for CloudWatch.

    Lambda function

    I chose to write the lambda function in Rust using the Rust Runtime for AWS [3] and the AWS SDK for Rust [4] — currently in developer preview. The implementation is fairly similar to the python implementation in [2] to the exception that I wanted to (a) check the email address against a blacklist and (b) forward the email content rather than a link to access the email from the S3 bucket.

    After installing rusta new binary application is created using cargo new ses_handler. The following dependencies are added to the Cargo.toml:

    • lambda_runtime — The glue required to write an AWS lambda function in Rust;
    • aws-types, aws-config, aws-sdk-ses and aws-sdk-s3 — Components of the Rust SDK to access to SES and S3 services;
    • mailparse to parse the email received by SES and saved to S3. There are a number of libraries available — I started using this one and as it works satisfactorily I did not investigate any other one.

    The implementation is structured around the following 3 Rust structs:

    • The SesEvent struct maps the SES event into an object that identifies the email ID, sender, subject and list of destinations. The struct and its construction method is shown below. The construction method is intimately coupled with the SES incoming email event format [5] that is provided as the from_json method argument payload.
    • The Address struct stores the fields used by the lambda function when forwarding the email — the from field is used to store the email address to which the email was originally sent to, i.e [email protected]. This is used as the originator of the forwarded email. The key field stores the email address key, i.e anything.
    • Instances of the Address struct are constructed from the email address [email protected]. The key is used to decide whether the email is forwarded or not as shown below. For key that are not forwarded, the method returns a None option.
    • The above method is used in the following method that translates the SES event destinations into a list of addresses:
    • The final struct Mail does the heavy lifting of reading the email from the S3 bucket, parsing it, creating the email to be forwarded — only the text and html portions of the message are forwarded, no attachments— and sending it. The Mail struct is defined from the message_id — the identifier of the email given by the SES event. The other fields, config, clientand messageallow for caching of information in the event that a message is to be sent multiple times — an edge case if the email was part of a mailing list with different @mydomain.com addresses.
    • The email parsing is handled by the following function that extracts the subject, plain text, and HTML components of the email:
    • The implementation of the send functionality of the Mail struct is by far the heaviest part of the implementation and is shown below. The implementation is reasonably clear and straightforward: (a) initialise the AWS config, (b) read the incoming message from the S3 bucket, (c) create the SES message from the plain text and HTML content of the incoming message, (d) initialize the SES client and (e) send the message on…

    Using the above structs, the main function takes on the following form where the incoming event is processed into an SesEvent object.

    The SesEvent message id is used to create a Mail object and the SesEvent list of destinations is converted to Address that are used to call the send method of the Mail object.

    I have been using my [email protected] proof-of-concept for a few weeks with quite a bit of success. But as the blacklist is hardcoded, I am not updating it very often. Whilst there is room for improvement, the implementation of the proof-of-concept went quite smoothly despite my lack of familiarity with the SES service.

    The AWS Rust SDK works effectively with the AWS SES and S3 services — despite being in developer preview. I am currently using it with Amazon DynamoDB which is proving a little less stable currently.

    [1] https://news.ycombinator.com/item?id=31116861
    [2] https://aws.amazon.com/blogs/messaging-and-targeting/forward-incoming-email-to-an-external-destination/
    [3] https://aws.amazon.com/blogs/opensource/rust-runtime-for-aws-lambda/
    [4] https://aws.amazon.com/sdk-for-rust/
    [5] https://docs.aws.amazon.com/ses/latest/dg/receiving-email-action-lambda-event.html

    (ses) 2022 and aws charentenay email implement julien jun, masking programming proof-of-concept rust sdk: service simple using
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Swave Digest
    • Website
    • Twitter
    • Pinterest

    Related Posts

    How This Amazing Campaign Succeeded in Changing a Brand’s Perception and People’s Lives at the Same Time

    June 29, 2022

    NFT and Digital Asset Authentication Technology Launches on KuCoin June 30th

    June 29, 2022

    Best Caribbean cruise tips to help you make the most of your time aboard and ashore

    June 29, 2022

    Fashion School Diaries: The Regent’s University London Graduate Inspired by Hugs and ‘Unclecore’

    June 29, 2022
    Add A Comment

    Leave A Reply Cancel Reply

    Twitter Instagram Pinterest
    • Home
    • Privacy Policy
    • Terms & Conditions
    • Contact Us
    © 2022 Swave Digest. All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.

    Posting....
    We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
    In case of sale of your personal information, you may opt out by using the link Do not sell my personal information.
    Cookie settingsACCEPT
    Manage consent

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
    Necessary
    Always Enabled
    Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
    CookieDurationDescription
    cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
    cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
    cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
    cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
    cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
    viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
    Functional
    Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
    Performance
    Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
    Analytics
    Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
    Advertisement
    Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
    Others
    Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
    Save & Accept