juanhurtado10 / serverless-contact-email

AWS Serverless infrastructure to handle contact emails in your static websites

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serverless backend for contact emails

The code in this repo allows you to deploy with ease an AWS Serverless infrastructure to handle contact requests in your static website. Before to start make sure you own an email verified in the AWS SES service. How to?

Project explanation

The serverless function is responsible to build and send a message to a specific email, as long as it receives the necessary parameters, otherwise return an error.

Test case:

You are a client, and you fill out and submit a form inside a static website:

  • The static website is going to send a request to this serverless function.
  • This function will receive the request and will validate all parameters.
  • If the request has the correct parameters, then the function is going to build and send a message to the email specified, in the serverless.json file, using Amazon SES. Otherwise, the function throws an exception and returns an error message.
  • Finally, the function returns a response with its respective HTTP status code.

Successful case: a request from postman to the serverless function

sendEmailNew

Failed case: No message in the request

error message

Configuration and deployment

1. Clone this repo

$ git clone git@github.com:kommitters/serverless-contact-form.git

2. Install the Serverless Framework

$ npm i -g serverless

Note: If you're using Linux, you may need to run the command as sudo.

3. Configure your AWS credentials

$ serverless config credentials \
    --provider aws \
    --key xxxxxxxxxxxxxx \
    --secret xxxxxxxxxxxxxx

4. Update the secrets file

{
  "NODE_ENV":"dev",
  "EMAIL":"john.doe@mail.com",
  "DOMAIN":"*"
}

⚠️ While testing you can keep the domain as '*', however, make sure to change this to your actual domain in production. The EMAIL field should contain an email you verified with AWS SES.

5. Deploy the API to AWS Lambda

$ serverless deploy

6. Test the API Gateway Endpoint

with CURL:

$ curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"email":"john.doe@email.com","name":"John Doe","message":"Hey!","phone":"12345"}' \
  https://{id}.execute-api.{region}.amazonaws.com/{stage}/email/send

With Postman:

postman

7. You are done!

Ready to send contact emails from your static website! 💪.

Contributing

Bug reports and pull requests are welcome on GitHub https://github.com/kommitters/serverless-contact-email. Everyone is welcome to participate in the project. If you are thinking about contributing to the project, please check our Contributing Guide.

Changelog

See the CHANGELOG for versions details.

License

See LICENSE for details.

Credits

Made with 💙 by kommit

About

AWS Serverless infrastructure to handle contact emails in your static websites

License:MIT License


Languages

Language:JavaScript 100.0%