How to configure MailerSend on Google Cloud
This guide describes how to configure your Google Cloud instance to begin sending emails using the MailerSend email API or SMTP relay.
MailerSend offers two plan types for Google Cloud users: Starter and Professional. Learn more about the MailerSend plans available for Google Cloud.
How to get started: Configuring Google Cloud
Select an existing Google Cloud project or create a new one from the Google Cloud Dashboard.
Sign up for a MailerSend subscription from Google Cloud Marketplace.
Add and verify a sending domain in MailerSend. To do this:
a) Go to the Domains page and click Add domain. Enter a name for your domain and click Add domain again.
b) In the pop-up, click Continue to add your domain automatically, or close the pop-up to view the DNS records and add your domain manually.
c) When you’ve added them, select the option ‘I have added DNS records’ and click Verify domain. For more information about adding and verifying a domain, check out the domain verification guide.
Alternatively you can use the API to add a domain and retrieve your DNS records.
Next, add an SMTP user for your domain or create an API token if you plan to send with the API.
To add an SMTP user:
a) Go to the Domains page, and click Manage for your domain.
b) In the SMTP section, click Generate new user. Enter a name and click Save user.
Your SMTP credentials will be generated. Click Save user again. You can view your SMTP credentials by clicking Manage. For more information about using SMTP, see the SMTP relay guide.
To create an API token:
a) Go to the Domains page, and click Manage for your domain.
b) In the API token section, click Generate new token.
c) Fill in the details for your API token and choose its permissions. Then click Create token.
d) Click Download to save a copy of your API token.
For more information about API tokens, check out our guide on Managing API tokens.
Again, you can use the API to add and manage SMTP users and API tokens.
Make sure you configure your SMTP settings in Google Cloud as the following:
- Configure firewall rules to allow TCP traffic on port 587
- Host: smtp.mailersend.net
Configure MailerSend as an SMTP relay on Google Cloud
The following steps will allow you to connect to your instance and run MailerSend with Postfix.
Connect to your VM using SSH, replacing instance-name with the name of the instance you want to send messages from:
gcloud compute ssh instance-name
On the VM, install the Postfix Mail Transport Agent. When prompted, accept the default choices for domain names but select the Local Only configuration.
Debian:
sudo apt update && sudo apt -y install postfix libsasl2-modules
CentOS:
sudo yum install postfix cyrus-sasl-plain cyrus-sasl-md5 -y
Modify the Postfix configuration options. You can do this by editing the main.cf file.
sudo vi /etc/postfix/main.cf
Update the file by commenting out the following lines:
# default_transport = error
# relay_transport = error
And add the following lines to the end of the file:
relayhost = [smtp.mailersend.net]:587
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
relayhost adds MailerSend’s SMTP service while the other lines enforce SSL/TLS support and configure SMTP authentication with a simple access and security layer (SASL) module.
c) Save the changes and close the file.
Create the SASL password map:
sudo vi /etc/postfix/sasl_passwd
To add your MailerSend credentials, add the following lines to the sasl_passwd file:
[smtp.mailersend.net]:587 YOUR_SMTP_USERNAME:YOUR_SMTP_PASSWORD
Use the postmap utility to generate a .db file:
sudo postmap /etc/postfix/sasl_passwd
sudo ls -l /etc/postfix/sasl_passwd*
You should receive the following response:
-rw------- 1 root root 68 Jun 1 10:50 /etc/postfix/sasl_passwd
-rw------- 1 root root 12288 Jun 1 10:51 /etc/postfix/sasl_passwd.db
The file containing your credentials is no longer needed, so you can remove it.
sudo rm /etc/postfix/sasl_passwd
Set the permissions on your .db file:
sudo chmod 600 /etc/postfix/sasl_passwd.db
sudo ls -la /etc/postfix/sasl_passwd.db
Reload your configuration to load the modified parameters:
Debian:
sudo /etc/init.d/postfix restart
CentOS:
sudo postfix reload
Install the mailx or mailutils package and test your configuration.
Debian:
sudo apt -y install mailutils
CentOS:
sudo yum install mailx -y
Use the following line to send a test message, replacing from-email with a validated email address, and destination-email with the address you would like to send the test email to.
echo 'Test passed.' | mail -s 'Test-Email' -aFrom:from-email destination-email
Check your system's logs for the status and the successful server response code (250):
Debian:
sudo tail -n 5 /var/log/syslog
CentOS:
sudo tail -n 5 /var/log/maillog
For more examples and information, check out our API and developer documentation.
Need more info?
Feel free to reach out to support@mailersend.com. A member of our support team will gladly assist you.
- Getting started
- FAQ
-
Features
- Sending domains
- Managing API tokens
- Domain tracking options
- How to add a domain space to your account
- SMTP relay
- Webhooks
- Inbound routing
- Templates
- How to add a survey to your emails
- Email tagging
- File manager
- Email and recipient activity
- Analytics
- Split Testing
- How to use personalization in emails
- How to use the MailerSend iOS app
- Schedule bulk emails with the bulk endpoint
- Ensuring secure SMS communication: Verification and usage limits
- SMS: How to handle opt-in and opt-out
- Custom headers
- Upcoming changes to TLS Protocol support
- How to request a dedicated IP
- Deliverability
- Account settings
- Billing
- Integrations