Coder Social home page Coder Social logo

marcusmonteirodesouza / google-cloud-self-hosted-smtp-server-email-sending Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 80 KB

Example of how to send emails using a self-hosted SMTP server in Google Cloud

JavaScript 9.17% HCL 87.73% Shell 3.09%
cloud-functions cloudbuild email gcp google-cloud nodejs smtp smtp-server terraform

google-cloud-self-hosted-smtp-server-email-sending's Introduction

Google Cloud - Self-Hosted Email Sending

This is an example of how to send emails in Google Cloud using a self-hosted email server running Mail-in-a-Box.

System Overview

Architecture Diagram

system architecture diagram

Components

Pub/Sub triggered Cloud Function that sends emails using by connecting to a SMTP server.

It expects a message with the following structure:

{
  "to": "[email protected]",
  "subject": "My email subject",
  "body": "<h1>The email body can be html</h1>"
}

Email Server

A virtual machine instance running Mail-in-a-Box.

Deployment

The system is deployed using terraform, running in Cloud Build.

Pre-requisites

  1. Create a Google Cloud Organization.
  2. Contact Google to allow your organization to make outbound connections to TCP port 25. Google blocks it by default.
  3. Install terraform.
  4. Install the gcloud CLI.
  5. Have a domain name and access to the domain's DNS. You will need to add a TXT record to prove to Google that you own the email_server_hostname.

Bootstrap

This is the process that creates the Google Cloud Project, enables the required APIs, and grants the necessary permissions to the Service Accounts, including the ones required for the Cloud Build Service Account to deploy the system.

  1. Run gcloud auth login
  2. Run gcloud auth application-default login.
  3. cd into the deployment/google-cloud/terraform/bootstrap folder.
  4. Comment out the entire contents of the deployment/google-cloud/terraform/bootstrap/backend.tf file.
  5. Create a terraform.tfvars file and add your variables' values. Leave the sourcerepo_name empty for now.
  6. Run terraform init.
  7. Run terraform apply -target=module.project.
  8. Uncomment the deployment/google-cloud/terraform/bootstrap/backend.tf file's contents and add the value of the tfstate_bucket output as the value of the bucket attribute.
  9. Run terraform init and answer yes.
  10. Create a Cloud Source Repository in the project your just created. Optionally, fork this repository and create a Cloud Source Repository by mirroring your forked repo. Update the sourcerepo_name variable with the repository name.
  11. Run terraform apply.

Deployment

This is a Cloud Build build that actually deploys the system.

  1. The pipeline can be triggered by either:
    • Push a commit to your Cloud Source Repository or to your Github fork.
    • Go to your project's Cloud Build Dashboard and manually run the push-to-branch-deployment trigger.
  2. The first time the deployment build runs it will fail, unless you have already verified the email_server_hostname's with Google before. You will see the domain verification instructions in the build error. Verify your domain, then add the Cloud Build Service Account as an owner, and then run the build again.
  3. Follow the Mail-in-a-Box setup guide to maximize the deliverability of your emails.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.