Go Mail - A cross platform mail driver for GoLang.

Overview

Gopher

Go Mail

A cross platform mail driver for GoLang.

Travis Software License Coverage Status Go Report Card GoDoc

Introduction

Go Mail aims to unify multiple popular mail API's (SparkPost, MailGun & SendGrid) into a singular easy to use interface. Email sending is seriously simple and great for allowing the developer to choose what platform they use.

cfg := mail.Config{
    URL:         "https://api.eu.sparkpost.com",
    APIKey:      "my-key",
    FromAddress: "[email protected]",
    FromName:    "Gopher",
}

driver, err := mail.NewClient(mail.SparkPost, cfg)
if err != nil {
    fmt.Println(err)
    return
}

tx := &mail.Transmission{
    Recipients:  []string{"[email protected]"},
    Subject:     "My email",
    HTML:        "

Hello from go mail!

"
, } result, err := driver.Send(tx) if err != nil { fmt.Println(err) return } fmt.Println(result)

Installation

go get -u github.com/ainsleyclark/go-mail

Supported API's

Currently, Sparkpost, MailGun and SendGrid is supported, if you want to see more, just submit a feature request or create a new Driver and submit a pull request.

API Dependency Examples
SparkPost github.com/SparkPost/gosparkpost Here
MailGun github.com/mailgun/mailgun-go/v4 Here
SendGrid github.com/sendgrid/sendgrid-go Here

Docs

Documentation can be found at the Go Docs, but we have included a kick start guide below to get you started.

Creating a new client:

The driver type is the first argument to be passed to the NewClient function, being one of the following:

  • mail.SparkPost
  • mail.MailGun
  • mail.SendGrid

A new configuration type is needed to create a new mailer as the second argument, each platform requires its own data, for example, MailGun requires a domain, but SparkPost doesn't. This is based of the requirements for the API. For more details see the examples above.

cfg := mail.Config{
    URL:         "https://api.eu.sparkpost.com",
    APIKey:      "my-key",
    FromAddress: "[email protected]",
    FromName:    "Gopher",
}

driver, err := mail.NewClient(mail.SparkPost, cfg)
if err != nil {
    fmt.Println(err)
    return
}

Sending Data

A transmission is required to transmit to a mailer as shown below. Once send is called, a mail.Result and error will be returned indicating if the transmission was successful.

tx := &mail.Transmission{
    Recipients: []string{"[email protected]"},
    Subject:    "My email",
    HTML:       "

Hello from go mail!

"
, PlainText: "plain text", } result, err := driver.Send(tx) if err != nil { fmt.Println(err) return } fmt.Println(result)

Adding attachments:

Adding attachments to the transmission is as simple as passing a byte slice and filename, Go Mail takes care of the rest for you.

image, err := ioutil.ReadFile("gopher.jpg")
if err != nil {
    fmt.Println(err)
    return
}

tx := &mail.Transmission{
    Recipients: []string{"[email protected]"},
    Subject:    "My email",
    HTML:       "

Hello from go mail!

"
, PlainText: "plain text", Attachments: mail.Attachments{ mail.Attachment{ Filename: "gopher.jpg", Bytes: image, }, }, }

Todo

  • Add CC & BCC

Contributing

We welcome contributors, but please read the contributing document before making a pull request.

Licence

Code Copyright 2021 go mail. Code released under the MIT Licence.

Issues
  • Mailgun

    Mailgun

    Great package!

    The only problem I am running into, and I'm sure it's me, is that when I try to send through mailgun, my HTML message gets rendered in the mail client with the wrong content type (text/plain).

    Below is the code used to send, and below is the sample email (raw) received.

    That is, the message displayed in the browser appears to have the correct payload, but the user gets to read raw html rather than a nicely formatted message.

    Any idea what I'm doing wrong?

    cfg := mail.Config{
        URL:         "https://api.mailgun.net/",
        APIKey:      "someapikey",
        FromAddress: mailMessage.FromAddress,
        FromName:    mailMessage.FromName,
        Domain:      "mg.mydomain.com",
    }
    
    driver, err := mail.NewClient(mail.MailGun, cfg)
        if err != nil {
        fmt.Println(err)
    }
    
    var toSlice []string
    toSlice = append(toSlice, mailMessage.ToAddress)
    
    formattedMessage = "<h1>Hello, world</h1>"
    plainText := "Hello, world"
    
    tx := &mail.Transmission{
        Recipients: toSlice,
        Subject:    mailMessage.Subject,
        HTML:       formattedMessage,
        PlainText: plainText,
    }
    
    rs, err := driver.Send(tx)
        if err != nil {
        fmt.Println(err)
    }
    
    fmt.Println(rs)
    

    And here is the resulting message:

    Delivered-To: [email protected] Received: by 2002:a05:6602:2816:0:0:0:0 with SMTP id d22csp709301ioe; Sun, 11 Apr 2021 06:46:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYhhmrpu7UvmoOFLE1Vl0fb2bUd4fYYpfMjrIacwmORyXF9WkHqNdSgejUFlyJNHcr/vT2 X-Received: by 2002:a05:6820:451:: with SMTP id p17mr19136528oou.93.1618148815224; Sun, 11 Apr 2021 06:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618148815; cv=none; d=google.com; s=arc-20160816; b=g2Sc5tbiMNl9Lk6GDXfByhcD4pjTiA1zIArM+FhOttmsqvMirqnoE3ZO1K/Q5nHWb4 q5Dx/WNm3a8OiR8d/bg9/XKrK3oFGc5lT6TtEDWi1/RqfYiTdywD5pK2Ug+EoGBQfQBb S1kAqKeka9iYqdQ665link5rBySB602ZuEekGvFDqvzdwPchlOLIkye5Ggr/RIbKcuYf 7JWehr8bSuX1RsTFTCfv6ojJozPDmEdtF6tbAxOca2bA0W6oCqesFC0e0BfdBHu9vhYK IAapYpx7YVLaFwPAgLP6O+POU374Av+19Is9W+dgP0nhA5JvZFCiwnSmhEl9L/l9YSd4 INlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:subject:from:to:message-id:sender:date :content-transfer-encoding:dkim-signature:dkim-signature; bh=CBs4VIi+Hgt2a2XJuW2wr7q/kVgtt7M5U3mvhqs5674=; b=aV7Kc/3pE6pwJZPHAZwqkSVeUCmsDGs777s/ko+Zo53JiMy8nk8IDU92Zef8lDXHS8 9sfejXMiG3Sw4MgiekT8vaul8QgiXgPPnD6m3KhCif+h1AJ7k/y/scvxFeXi8l5bhVMo 8oo1ioE5Xy6UOfK7JQxECnhgQz25VaytycvtEhxB6Rtf6wkRVrrOONB9B4VS8JwU3EzG zQ3y/Qzvisivlb50s1FBDnScBKE6eGQx15rsPxyb/hVWPDcR8VkNsmRVfNkX4n22Y3oZ E8hVsySOo8/ht9/ImMMfPqVC9dwkHg3vZqq15t8X/+WNrWD/gq/DpElPX3urORIFmMZU 7WcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass [email protected] header.s=pic header.b=VlTzhdjS; dkim=pass [email protected] header.s=mg header.b=uysNa81o; spf=pass (google.com: domain of [email protected] designates 209.61.151.241 as permitted sender) smtp.mailfrom="[email protected]" Return-Path: [email protected] Received: from rs241.mailgun.us (rs241.mailgun.us. [209.61.151.241]) by mx.google.com with UTF8SMTPS id c189si9473199oif.183.2021.04.11.06.46.51 for [email protected] (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Apr 2021 06:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of [email protected] designates 209.61.151.241 as permitted sender) client-ip=209.61.151.241; Authentication-Results: mx.google.com; dkim=pass [email protected] header.s=pic header.b=VlTzhdjS; dkim=pass [email protected] header.s=mg header.b=uysNa81o; spf=pass (google.com: domain of [email protected] designates 209.61.151.241 as permitted sender) smtp.mailfrom="[email protected]" DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.somedomain.com; q=dns/txt; s=pic; t=1618148815; h=Mime-Version: Content-Type: Subject: From: To: Message-Id: Sender: Date: Content-Transfer-Encoding: X-Feedback-Id; bh=CBs4VIi+Hgt2a2XJuW2wr7q/kVgtt7M5U3mvhqs5674=; b=VlTzhdjShoQVADb+knojm1mrleJz3KUO4l4Hc20/8rjfG52nYM4JD9Y2Jcc/hCqGbFUunmgd WfhyQtPSwqkw8JWBH2vqRZHyjVWvI58C4C8Wpwuhp84+NTlgO7w9ZtmnoBo8uWyr6kqfzTsS tkxC773nMW0Jb6vv2scwPKgiJm8= DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mailgun.org; q=dns/txt; s=mg; t=1618148815; h=Mime-Version: Content-Type: Subject: From: To: Message-Id: Sender: Date: Content-Transfer-Encoding: X-Feedback-Id; bh=CBs4VIi+Hgt2a2XJuW2wr7q/kVgtt7M5U3mvhqs5674=; b=uysNa81oWS2WPuiiJHGtDTSclAKGgshDcOlfgr3WM5F1LKdaiKE+d8M7bo/MKVehvZR2y1/3 D2w2D604OHt4bXiBe2OIhIxecAeTiIzdfMtLSiDArreCLSCTDlTg5PPZJoK6Ew6quk44283s nEn1iJ6Fs9d/QLnZmVBEM6EJG0c= X-Feedback-Id: 589e0b0bcd1682225498c986:mailgun X-Mailgun-Sending-Ip: 209.61.151.241 X-Mailgun-Sid: WyI2MDliMSIsICJ0cmV2b3Iuc2F3bGVyQGdtYWlsLmNvbSIsICI1ZDdiZTAiXQ== Content-Transfer-Encoding: 7bit Received: by luna.mailgun.net with HTTP; Sun, 11 Apr 2021 13:46:31 +0000 Date: Sun, 11 Apr 2021 13:46:31 +0000 Sender: [email protected] Message-Id: [email protected] To: [email protected] From: [email protected] Subject: Password Reset Request Content-Type: text/plain; charset="ascii" Mime-Version: 1.0

    Hello, world

    bug good first issue 
    opened by tsawler 4
  • Support SMTP

    Support SMTP

    It would be great if plain old SMTP was supported.

    For development, and for apps which only sends a few mails, I often use Gmail's SMTP or other SMTP servers.

    enhancement 
    opened by tonsV2 2
Releases(v1.0.3)
  • v1.0.2(Apr 12, 2021)

    New SMTP Driver (non TLS).

    func SMTP() {
    	cfg := mail.Config{
    		URL:         "smtp.gmail.com",
    		FromAddress: "[email protected]",
    		FromName:    "Gopher",
    		Password:    "my-password",
    		Port:        587,
    	}
    
    	driver, err := mail.NewClient(mail.SMTP, cfg)
    	if err != nil {
    		fmt.Println(err)
    		return
    	}
    
    	tx := &mail.Transmission{
    		Recipients: []string{"[email protected]"},
    		Subject:    "My email",
    		HTML:       "<h1>Hello from go mail!</h1>",
    		PlainText:  "plain text",
    	}
    
    	result, err := driver.Send(tx)
    	if err != nil {
    		fmt.Println(err)
    		return
    	}
    
    	fmt.Println(result)
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Apr 12, 2021)

    Fixed MailGun not rendering HTML

    mailgun.go

    message := m.client.NewMessage(m.cfg.FromAddress, t.Subject, t.PlainText, t.Recipients...)
    message.SetHtml(t.HTML)
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 8, 2021)

    This is the first release of the application which supports the following frameworks: SparkPost, MailGun, SendGrid Users should reference the README.md for more information, it is kept up to date with releases.

    Source code(tar.gz)
    Source code(zip)
Owner
Ainsley Clark
Front-End Developer HTML5 | CSS3 | JavaScript | Java | SQL | jQuery | SASS
Ainsley Clark
Golang package that generates clean, responsive HTML e-mails for sending transactional mail

Hermes Hermes is the Go port of the great mailgen engine for Node.js. Check their work, it's awesome! It's a package that generates clean, responsive

Mathieu Cornic 2.4k Dec 5, 2021
๐Ÿ“ง Example of sending mail via SendGrid in Golang.

?? go-sendgrid-example Example of sending mail via SendGrid in Golang. Get it started $ make setup # Edit environment variables $ vim ./env/local.env

ducci 1 Nov 13, 2021
:envelope: A streaming Go library for the Internet Message Format and mail messages

go-message A Go library for the Internet Message Format. It implements: RFC 5322: Internet Message Format RFC 2045, RFC 2046 and RFC 2047: Multipurpos

Simon Ser 228 Nov 28, 2021
Go library for sending mail with the Mailgun API.

Mailgun with Go Go library for interacting with the Mailgun API. Usage package main import ( "context" "fmt" "log" "time" "githu

Mailgun Team 562 Nov 25, 2021
โœ‰๏ธ Composable all-in-one mail server.

Maddy Mail Server Composable all-in-one mail server. Maddy Mail Server implements all functionality required to run a e-mail server. It can send messa

Max Mazurov 2.8k Dec 3, 2021
MIME mail encoding and decoding package for Go

enmime enmime is a MIME encoding and decoding library for Go, focused on generating and parsing MIME encoded emails. It is being developed in tandem w

James Hillyerd 271 Nov 9, 2021
an MDA that sends a webhook on recieval of mail

an MDA that sends a webhook on recieval of mail

forlater 7 Oct 4, 2021
DKIM package for golang

go-dkim DKIM package for Golang Getting started Install go get github.com/toorop/go-dkim Warning: you need to use Go 1.4.2-master or 1.4.3 (when it

Stรฉphane Depierrepont 73 Oct 10, 2021
Golang package for send email. Support keep alive connection, TLS and SSL. Easy for bulk SMTP.

Go Simple Mail The best way to send emails in Go with SMTP Keep Alive and Timeout for Connect and Send. IMPORTANT Examples in this README are for v2.2

Santiago De la Cruz 230 Nov 23, 2021
The Official Twilio SendGrid Led, Community Driven Golang API Library

NEW: Subscribe to email notifications for releases and breaking changes. The default branch name for this repository has been changed to main as of 07

Twilio SendGrid 778 Nov 25, 2021
An email MIME artist for golang

Marcel is a tool to generate IETF compliant emails in raw MIME format. I mainly use this for generating emails with attachments and sending them via amazon SES. If that's what you're doing too, you may want notifications

David Banham 21 Sep 27, 2021
EMail Searcher By Golang

GiveMeMail โ–„โ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–“ โ–ˆโ–ˆโ–’ โ–ˆโ–ˆโ–“ โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–„ โ–„โ–ˆโ–ˆโ–ˆโ–“โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–„ โ–„โ–ˆโ–ˆโ–ˆโ–“ โ–ˆโ–ˆ โ–ˆโ–ˆโ–“ โ–ˆโ–ˆโ–“ โ–ˆโ–ˆโ–’ โ–€โ–ˆโ–’ โ–“โ–ˆโ–ˆโ–’ โ–“โ–ˆโ–ˆโ–‘ โ–ˆโ–’ โ–“โ–ˆ โ–€ โ–“โ–ˆโ–ˆโ–’โ–€โ–ˆโ–€ โ–ˆโ–ˆโ–’โ–“โ–ˆ

ConsT27 9 Oct 20, 2021
go-pst is a library for reading PST files (written in Go/Golang).

go-pst A library for reading PST files (written in Go/Golang). Introduction go-pst is a library for reading PST files (written in Go/Golang). The PFF

Mooij Technologies 100 Dec 3, 2021
golang honeypot smtp server

honeygogo-smtp standalone honeypot A lightweight SMTP honeypot server written in Go, leveraging go-smtp. A stand alone version of a module from honeyg

jothflee 0 Nov 11, 2021
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package

Go-MySQL-Driver A MySQL-Driver for Go's database/sql package Features Requirements Installation Usage DSN (Data Source Name) Password Protocol Address

Go SQL Drivers 11.7k Dec 2, 2021
Qmgo - The Go driver for MongoDB. Itโ€˜s based on official mongo-go-driver but easier to use like Mgo.

Qmgo English | ็ฎ€ไฝ“ไธญๆ–‡ Qmgo is a Go driver for MongoDB . It is based on MongoDB official driver, but easier to use like mgo (such as the chain call). Qmg

Qiniu Cloud 740 Dec 3, 2021
Go driver for PostgreSQL over SSH. This driver can connect to postgres on a server via SSH using the local ssh-agent, password, or private-key.

pqssh Go driver for PostgreSQL over SSH. This driver can connect to postgres on a server via SSH using the local ssh-agent, password, or private-key.

mattn 48 Nov 23, 2021
Devcloud-go provides a sql-driver for mysql which named devspore driver and a redis client which named devspore client,

Devcloud-go Devcloud-go provides a sql-driver for mysql which named devspore driver and a redis client which named devspore client, you can use them w

HUAWEI CLOUD 9 Nov 29, 2021
:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving

Package validator Package validator implements value validations for structs and individual fields based on tags. It has the following unique features

Go Playgound 9.2k Dec 2, 2021
๐Ÿ’ฏ Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving

Package validator implements value validations for structs and individual fields based on tags.

Flamego 10 Oct 24, 2021
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 9.2k Dec 6, 2021
Cross platform locale detection for Golang

go-locale go-locale is a Golang lib for cross platform locale detection. OS Support Support all OS that Golang supported, except android: aix: IBM AIX

Xuanwo 79 Nov 28, 2021
Cross platform locale detection for Golang

go-locale go-locale is a Golang lib for cross platform locale detection. OS Support Support all OS that Golang supported, except android: aix: IBM AIX

Xuanwo 79 Nov 28, 2021
Cross platform rapid GUI framework for golang based on Dear ImGui.

giu Cross platform rapid GUI framework for golang based on Dear ImGui and the great golang binding imgui-go. Any contribution (features, widgets, tuto

Allen Dang 1.1k Nov 29, 2021
hotbuild - a cross platform hot compilation tool for golang

hotbuild A cross platform hot compilation tool By monitoring the modification of the project directory file, the recompilation and running are automat

wander 135 Dec 1, 2021
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 9.1k Nov 26, 2021
A cross platform CLI for Flyte. Written in Golang. Offers an intuitive interface to Flyte https://flytectl.readthedocs.io/en/latest/

FlyteCTL Flyte's official command-line interface Documentation ยท Contribution Guide FlyteCTL was designed as a portable and lightweight command-line i

Flyte 21 Nov 30, 2021
Inline styling for html mail in golang

go-premailer Inline styling for HTML mail in golang Document install go get github.com/vanng822/go-premailer/premailer Example import ( "fmt" "gith

Nguyen Van Nhu 77 Nov 23, 2021
Golang package that generates clean, responsive HTML e-mails for sending transactional mail

Hermes Hermes is the Go port of the great mailgen engine for Node.js. Check their work, it's awesome! It's a package that generates clean, responsive

Mathieu Cornic 2.4k Dec 5, 2021