Stay organized with collections Save and categorize content based on your preferences.
Mailjet is a third-party global email service that offers Compute Engine users a free tier with 6,000 emails each month. In addition, Mailjet also offers:
gmail.com
.This document describes how to configure your VM instance to send mail through Mailjet using the following methods:
For extensive documentation of other email solutions, including examples of integration with most common SMTP servers, libraries, and frameworks, see Mailjet's documentation.
Before you beginCreate a new Mailjet account on Mailjet's Google partner page*. When signing up, provide the domain and email address from which you want to send email messages.
Make sure the email address you want to send emails from has been validated.
Set up a firewall rule to allow TCP traffic on port 2525.
* Google is compensated for customers who sign up for a non-free account.
Configuring Mailjet as an SMTP relayConfiguring Mailjet as a mail relay lets you forward email messages to Mailjet for remote delivery.
Using PostfixConnect to your VM using SSH, replacing instance-name
with the name of the instance you want to send email 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.
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. Postfix configuration options are set in the main.cf
file. Open the file with the text editor of your choice:
sudo vi /etc/postfix/main.cf
Update the file:
Comment out the following lines:
# default_transport = error
# relay_transport = error
Add the following lines to the end of the file:
relayhost = in-v3.mailjet.com:2525
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
These lines enforce SSL/TLS support and configure SMTP authentication for these requests. A simple access and security layer (SASL) module handles authentication in the Postfix configuration.
Note: You must use port 2525 because port 25 is not allowed on Compute Engine.Save your changes and close the file.
Create the SASL password map with the text editor of your choice:
sudo vi /etc/postfix/sasl_passwd
To the sasl_passwd
file, add the following lines to provide the credentials for Mailjet:
in-v3.mailjet.com:2525 YOUR_API_KEY:YOUR_SECRET_KEY
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
Next, remove the file that contains your credentials because it is no longer needed:
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
Finally, reload your configuration to load the modified parameters:
Debiansudo /etc/init.d/postfix restart
CentOS
sudo postfix reload
Test your configuration. Install the mailx
or mailutils
package and test your configuration.
sudo apt -y install mailutils
CentOS
sudo yum install mailx -y
Send a test message:
echo 'Test passed.' | mail -s 'Test-Email' -aFrom:from-email destination-email
Replace the following:
from-email
: An email address that has been validated.destination-email
: The address to send the email message to.Look in your system's logs for a status line containing status
and the successful server response code (250)
:
sudo tail -n 5 /var/log/syslog
CentOS
sudo tail -n 5 /var/log/maillog
If you run into issues setting up Postfix with Mailjet, see the Mailjet Postfix setup instructions.
Using NodemailerThe following instructions describe how to use Mailjet with Node.js on Debian Wheezy.
Debiangcloud compute ssh instance-name
user@test-wheezy:~# sudo apt update
user@test-wheezy:~# sudo apt -y install git-core curl build-essential openssl libssl-dev
user@test-wheezy:~# git clone https://github.com/nodejs/node
user@test-wheezy:~# cd node
user@test-wheezy:~# ./configure
user@test-wheezy:~# sudo make
This can take a few minutes to complete.
user@test-wheezy:~# sudo make install
user@test-wheezy:~# npm install nodemailer nodemailer-smtp-transport
node
directory, create a new file named sendmail.js
that contains the following JavaScript:user@test-wheezy:~# node sendmail.js
gcloud compute ssh instance-name
user@test-centos:~# sudo yum update -y
user@test-centos:~# sudo yum install git-core curl openssl openssl-dev -y ... user@test-centos:~# sudo yum groupinstall "Development Tools" -y ...
user@test-centos:~# git clone https://github.com/nodejs/node
user@test-centos:~# cd node
user@test-centos:~# ./configure
user@test-centos:~# sudo make
This can take a few minutes to complete.
user@test-centos:~# sudo make install
user@test-centos:~# npm install npm install nodemailer nodemailer-smtp-transport
node
directory, create a new file named sendmail.js
that contains the following JavaScript:user@test-centos:~# node sendmail.js
For more examples of using the Mailjet API, see the official Mailjet documentation.
Debiangcloud compute ssh instance-name
user@test-instance:~# sudo apt update && sudo apt install git-core openjdk-8-jdk maven
user@test-instance:~# git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
/root/java-docs-samples/compute/mailjet/src/main/java/com/example/compute/mailjet
your-mailjet-api-key
: An API key for your Mailjet account.your-mailjet-secret-key
: The corresponding secret key for your Mailjet account.mailjet
directory, use Maven to package the class as a JAR file:
user@test-instance:~# mvn clean package
user@test-instance:~# sudo update-alternatives --config java
user@test-instance:~# java -jar compute-mailjet-1.0-SNAPSHOT-jar-with-dependencies.jar recipient-email sender-email
gcloud compute ssh instance-name
user@test-centos:~# sudo yum update && sudo yum install git-core openjdk-8-jdk maven
user@test-centos:~# git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
/root/java-docs-samples/compute/mailjet/src/main/java/com/example/compute/mailjet
your-mailjet-api-key
: An API key for your Mailjet account.your-mailjet-secret-key
: The corresponding secret key for your Mailjet account.mailjet
directory, use Maven to package the class as a JAR file:
user@test-centos:~# mvn clean package
user@test-centos:~# sudo alternatives --config java
user@test-centos:~# java -jar compute-mailjet-1.0-SNAPSHOT-jar-with-dependencies.jar recipient-email sender-email
Here is a quick reference to Mailjet-specific SMTP settings that are used to configure clients:
Explore reference architectures, diagrams, and best practices about Google Cloud. Take a look at our Cloud Architecture Center.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Mailjet provides Compute Engine users with a free tier of 6,000 emails per month and offers an API, user interface, and SMTP relay for sending transactional and marketing emails."],["Mailjet supports email sending through an SMTP relay using Postfix or Nodemailer, as well as directly through its API using Java."],["To start using Mailjet, users need to create a Mailjet account, obtain SMTP credentials, validate the sender email address, and configure a firewall rule to allow TCP traffic on port 2525."],["The supported features include an API resource library in multiple coding languages, 24/7 support, European data privacy compliance, integrated MJML framework, and customizable settings for deliverability."],["Mailjet utilizes the host 'in-v3.mailjet.com' and port '2525' for SMTP configurations, with detailed setup instructions provided for various methods and operating systems."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4