Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions guides-and-tips/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Welcome to Mailtrap Guides & Tips! This section provides detailed, step-by-step

Get started quickly with our official SDKs for your favorite programming language.

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><i class="fa-php">:php:</i> <strong>PHP</strong></td><td>Official PHP SDK for Mailtrap</td><td><a href="sdk/php-integration.md">php-integration.md</a></td><td></td></tr><tr><td><i class="fa-node-js">:node-js:</i> <strong>Node.js</strong></td><td>Official Node.js SDK for Mailtrap</td><td><a href="sdk/nodejs-integration.md">nodejs-integration.md</a></td><td></td></tr><tr><td><i class="fa-gem">:gem:</i> <strong>Ruby</strong></td><td>Official Ruby SDK for Mailtrap</td><td><a href="sdk/ruby-integration.md">ruby-integration.md</a></td><td></td></tr><tr><td><i class="fa-microsoft">:microsoft:</i> <strong>.NET</strong></td><td>Official .NET SDK for Mailtrap</td><td><a href="sdk/dotnet-integration.md">dotnet-integration.md</a></td><td></td></tr><tr><td><i class="fa-java">:java:</i> <strong>Java</strong></td><td>Official Java SDK for Mailtrap</td><td><a href="sdk/java-integration.md">java-integration.md</a></td><td></td></tr><tr><td><i class="fa-python">:python:</i> <strong>Python</strong></td><td>Official Python SDK for Mailtrap</td><td><a href="sdk/python-integration.md">python-integration.md</a></td><td></td></tr><tr><td><i class="fa-laravel">:laravel:</i> <strong>Laravel</strong></td><td>Laravel integration with Mailtrap PHP SDK</td><td><a href="sdk/php-integration.md">php-integration.md</a></td><td></td></tr><tr><td><i class="fa-symfony">:symfony:</i> <strong>Symfony</strong></td><td>Symfony integration with Mailtrap PHP SDK</td><td><a href="sdk/php-integration.md">php-integration.md</a></td><td></td></tr></tbody></table>
<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><i class="fa-php">:php:</i> <strong>PHP</strong></td><td>Official PHP SDK for Mailtrap</td><td><a href="sdk/php-integration.md">php-integration.md</a></td><td></td></tr><tr><td><i class="fa-node-js">:node-js:</i> <strong>Node.js</strong></td><td>Official Node.js SDK for Mailtrap</td><td><a href="sdk/nodejs-integration.md">nodejs-integration.md</a></td><td></td></tr><tr><td><i class="fa-gem">:gem:</i> <strong>Ruby</strong></td><td>Official Ruby SDK for Mailtrap</td><td><a href="sdk/ruby-integration.md">ruby-integration.md</a></td><td></td></tr><tr><td><i class="fa-microsoft">:microsoft:</i> <strong>.NET</strong></td><td>Official .NET SDK for Mailtrap</td><td><a href="sdk/dotnet-integration.md">dotnet-integration.md</a></td><td></td></tr><tr><td><i class="fa-java">:java:</i> <strong>Java</strong></td><td>Official Java SDK for Mailtrap</td><td><a href="sdk/java-integration.md">java-integration.md</a></td><td></td></tr><tr><td><i class="fa-python">:python:</i> <strong>Python</strong></td><td>Official Python SDK for Mailtrap</td><td><a href="sdk/python-integration.md">python-integration.md</a></td><td></td></tr><tr><td><i class="fa-golang">:golang:</i> <strong>Go</strong></td><td>Official Go SDK for Mailtrap</td><td><a href="sdk/go-integration.md">go-integration.md</a></td><td></td></tr><tr><td><i class="fa-laravel">:laravel:</i> <strong>Laravel</strong></td><td>Laravel integration with Mailtrap PHP SDK</td><td><a href="sdk/php-integration.md">php-integration.md</a></td><td></td></tr><tr><td><i class="fa-symfony">:symfony:</i> <strong>Symfony</strong></td><td>Symfony integration with Mailtrap PHP SDK</td><td><a href="sdk/php-integration.md">php-integration.md</a></td><td></td></tr></tbody></table>

Browse all SDK integration guides in the navigation menu for additional languages including Go, Elixir, Scala, and Perl.
Browse all SDK integration guides in the navigation menu for additional languages including Elixir, Scala, and Perl.

## Third-Party Integrations

Expand Down
114 changes: 107 additions & 7 deletions guides-and-tips/sdk/go-integration.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,87 @@
---
description: >-
Learn how to integrate Mailtrap with Go applications using SMTP and RESTful
API for email sending.
Integrate Mailtrap with Go apps and projects for email sending using SDK,
SMTP, or RESTful API
---

# Go

## Overview
<a href="https://github.com/mailtrap/mailtrap-go" class="button primary">Mailtrap Go SDK on GitHub</a>

### Overview

Mailtrap can be integrated with Go apps and projects for email sending.

## Email API/SMTP for Go
### Email API/SMTP for Go

#### SDK integration
Comment thread
coderabbitai[bot] marked this conversation as resolved.

The [Mailtrap Go SDK](https://github.com/mailtrap/mailtrap-go) provides an idiomatic Go interface for the full Mailtrap feature set, with `context.Context` support and typed errors on every call. The SDK supports:

* Transactional, bulk & batch email sending
* Email template management
* Sending domain management
* Suppression list management
* Webhook management
* Email logs and sending stats
* Sandbox email sending, projects, inboxes & message inspection
* Contact management (contacts, lists, fields, imports & exports)
* Account & organization management

### Installation

Install the SDK:

{% code title="Terminal" %}
```bash
go get github.com/mailtrap/mailtrap-go
```
{% endcode %}

Requires Go 1.23 or newer.

### Minimal Example

Here's a minimal example to send your first email:

{% code title="main.go" %}
```go
package main

import (
"context"
"fmt"
"log"

### SMTP integration
mailtrap "github.com/mailtrap/mailtrap-go"
)

func main() {
client, err := mailtrap.NewClient("your-api-token")
if err != nil {
log.Fatal(err)
}

resp, _, err := client.Send(context.Background(), &mailtrap.SendRequest{
From: mailtrap.Address{Email: "hello@example.com", Name: "Mailtrap Test"},
To: []mailtrap.Address{{Email: "recipient@example.com"}},
Subject: "Hello from Mailtrap!",
Text: "Welcome to Mailtrap Email Sending!",
HTML: "<p>Welcome to <strong>Mailtrap</strong> Email Sending!</p>",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.MessageIDs)
}
```
{% endcode %}

{% hint style="info" %}
Get your API token from your Mailtrap account under **Settings → API Tokens**.
{% endhint %}

#### SMTP integration

To integrate SMTP with your Go app, navigate to the **Integrations** tab and copy-paste the credentials.

Expand All @@ -22,9 +91,40 @@ SMTP integration is compatible with any Go framework or library that sends email

<div align="left" data-with-frame="true"><img src="../.gitbook/assets/mailtrap-go-smtp-integration.png" alt="" width="563"></div>

Read more about SMTP integration [here](https://app.gitbook.com/s/S3xyr7ba7aGO19rc8dSK/email-api-smtp/setup/smtp-integration).
The standard library's `net/smtp` package is all you need — no third-party dependencies:

{% code title="main.go" %}
```go
package main

import (
"log"
"net/smtp"
)

func main() {
// Copy host, port, username, and password from the Integrations tab.
host := "live.smtp.mailtrap.io"
auth := smtp.PlainAuth("", "api", "your-api-token", host)

msg := []byte("From: hello@example.com\r\n" +
"To: recipient@example.com\r\n" +
"Subject: Hello from Mailtrap!\r\n" +
"\r\n" +
"Welcome to Mailtrap Email Sending!\r\n")

err := smtp.SendMail(host+":587", auth, "hello@example.com",
[]string{"recipient@example.com"}, msg)
if err != nil {
log.Fatal(err)
}
}
```
{% endcode %}

Read more in the [SMTP integration guide](https://app.gitbook.com/s/S3xyr7ba7aGO19rc8dSK/email-api-smtp/setup/smtp-integration).

### RESTful API integration
#### RESTful API integration

To integrate Mailtrap using RESTful API, use the configuration available among **Code samples** under the API section.

Expand Down