Sending Email with Mailjet

Mailjet is a third-party global email service that offers App Engine users a free tier with 25,000 emails each month. In addition, Mailjet also offers:

  • An API, user interface, and SMTP relay to send transactional and marketing email.
  • European data privacy compliance.
  • Email and deliverability features such as customizable priority settings and automated throttle management.
  • API resource library in Go, PHP, Nodejs, Java, Python, Ruby to manage sub-accounts, authentication, contacts, campaigns, custom payloads, statistics, real time events and parsing through the Event API.
  • Integrated MJML framework to create responsive HTML email templates.
  • 24/7 follow-the-sun support in 4+ languages.
  • Ability to send emails from domains other than

Before you begin

Before you send mail with Mailjet:

  1. Create a Mailjet account. As a Google App Engine developer, you can start with 25,000 free emails per month.
  2. In Mailjet, add and verify the sender email address.
  3. Note your API key and secret from your Mailjet SMTP Settings.
  4. Select or create a GCP project.

    Go to the Manage resources page

Setting up

Use the Go wrapper for the Mailjet API to send emails from your application.

  1. Add the Mailjet package into your app folder:

    go get
  2. Import the library in your application code:

    import ""

Sending mail

To send a message in your application code:

  1. Create a new Mailjet client.

  2. Specify the details and contents of the message, including the sender email and name, subject, message body, and recipients.

  3. Retrieve the server response to check the message status.

For example:

func sendEmail(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)

	mailjetClient := mailjet.NewMailjetClient(


	to := r.FormValue("to")
	if to == "" {
		http.Error(w, "Missing 'to' parameter.", http.StatusBadRequest)

	messagesInfo := []mailjet.InfoMessagesV31{
			From: &mailjet.RecipientV31{
				Email: fromEmail,
				Name:  "Mailjet Pilot",
			To: &mailjet.RecipientsV31{
					Email: to,
					Name:  "passenger 1",
			Subject:  "Your email flight plan!",
			TextPart: "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
			HTMLPart: "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",

	messages := mailjet.MessagesV31{Info: messagesInfo}
	resp, err := mailjetClient.SendMailV31(&messages)
	if err != nil {
		msg := fmt.Sprintf("Could not send mail: %v", err)
		http.Error(w, msg, 500)

	fmt.Fprintf(w, "%d email(s) sent!", len(resp.ResultsV31))


The response payload of a Mailjet Send API call provides a MessageID. You can use the MessageID to access information and statistics about the message.

The Mailjet API's GET operation on /message returns basic information about a message such as the sender, recipient, and message size. It also returns the current state of the message, such as whether it was successfully sent. To learn more about message statistics, including sample API responses, refer to the Mailjet API guide.

Event API

The Mailjet Event API offers real-time notification through HTTP requests (webhooks) on any events related to the messages you sent, such as when messages are sent or opened. This event notification works for all kind of messages, from transactional to marketing campaigns.

Use the Event API to achieve specific actions efficiently, such as logging the marketing messages sent to your customers,or updating the unsubscribed contacts in your customer relationship management (CRM) system. Instead of polling the Mailjet API a few times a day, data is pushed events happen, in near real-time.

You can also group events together, which is useful when sending larger volumes. For further instructions, see the Mailjet documentation.

Parse API for inbound emails

You can also receive and parse emails with Mailjet and have the content delivered to a webhook. Mailjet organizes all the information so you can save it to your CRM or database.

Like the Event API, the Parse API notifies in near real-time to a defined webhook that sends data back to your application when a new message matches a predefined route. Emails are sent to your application structured as a JSON packet with all the useful information you need, such as the sender, recipient, subject, body and headers.

For more information, including additional fields sent with every email, and instructions for DNS setup and usage, see Mailjet’s Parse API documentation.

Sending email from Google Compute Engine

If your project uses Compute Engine to perform backend tasks that need to send email, you can also use Mailjet from Compute Engine.

Was this page helpful? Let us know how we did:

Send feedback about...

App Engine standard environment for Go