The best way to send emails in Go.

Related tags

Email gomail
Overview

Gomail

Build Status Code Coverage Documentation

Introduction

Gomail is a simple and efficient package to send emails. It is well tested and documented.

Gomail can only send emails using an SMTP server. But the API is flexible and it is easy to implement other methods for sending emails using a local Postfix, an API, etc.

It is versioned using gopkg.in so I promise there will never be backward incompatible changes within each version.

It requires Go 1.2 or newer. With Go 1.5, no external dependencies are used.

Features

Gomail supports:

  • Attachments
  • Embedded images
  • HTML and text templates
  • Automatic encoding of special characters
  • SSL and TLS
  • Sending multiple emails with the same SMTP connection

Documentation

https://godoc.org/gopkg.in/gomail.v2

Download

go get gopkg.in/gomail.v2

Examples

See the examples in the documentation.

FAQ

x509: certificate signed by unknown authority

If you get this error it means the certificate used by the SMTP server is not considered valid by the client running Gomail. As a quick workaround you can bypass the verification of the server's certificate chain and host name by using SetTLSConfig:

package main

import (
	"crypto/tls"

	"gopkg.in/gomail.v2"
)

func main() {
	d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
	d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

    // Send emails using d.
}

Note, however, that this is insecure and should not be used in production.

Contribute

Contributions are more than welcome! See CONTRIBUTING.md for more info.

Change log

See CHANGELOG.md.

License

MIT

Contact

You can ask questions on the Gomail thread in the Go mailing-list.

Issues
  • 504 5.7.4 Unrecognized authentication type

    504 5.7.4 Unrecognized authentication type

    From golang-nuts: https://groups.google.com/d/msg/golang-nuts/ywPpNlmSt6U/0Mxttkx9kgQJ

    mailer := gomail.NewMailer("smtp.office365.com", "[email protected]", "password", 587)
    

    Returns error 504 5.7.4 Unrecognized authentication type

    opened by alexcesaro 18
  • Cannot send email from docker container

    Cannot send email from docker container

    dialandsend return an error when inside a privileged docker container When inside a kubernetes, the error does not seem to happen, but the email do not get sended.

    web_1 | /api/register
    web_1 | 172.18.0.1 - - [10/Apr/2016:20:51:59 +0000] "POST /api/register HTTP/1.1" 200 78
    web_1 | http://localhost:9001/api/confirm/$2a$04$6Dad45u6SlTB7rWTNz2GzOc3j9jWOjT.1oTjfuvO5Bd8gKGwnvX56
    web_1 | panic: x509: failed to load system roots and no roots provided
    web_1 | 
    web_1 | goroutine 49 [running]:
    web_1 | panic(0x9f49c0, 0xe2e628)
    web_1 |         /usr/lib/go/src/runtime/panic.go:464 +0x3e6
    web_1 | bitbucket.org/cescoferraro/templatego/src/backend/api.SendRegisterEmail(0xc820210b60, 0x0, 0x0, 0xc8201f99d0, 0x9, 0xc8201fd540, 0x1b, 0xc820200b00, 0x3c, 0x0, ...)
    web_1 |         /home/cesco/code/go/src/bitbucket.org/cescoferraro/templatego/src/backend/api/register.go:85 +0x7af
    web_1 | created by bitbucket.org/cescoferraro/templatego/src/backend/api.RegisterEndPoint
    web_1 |         /home/cesco/code/go/src/bitbucket.org/cescoferraro/templatego/src/backend/api/register.go:55 +0x656
    templatego_web_1 exited with code 2
    
    opened by cescoferraro 14
  • go get fail

    go get fail

    somehow running the go get gopkg.in/gomail.v1 in centos 6 is not working.. it just stuck there for very very long. and i check the $GOPATH/src/gopkg.in folder its empty... and i have been very curious why is it not go get github.com/go-gomail/gomail instead...

    opened by badoet 14
  • AddAlternative bug

    AddAlternative bug

    ` message.SetBody("text/plain", "Hello pj")

    message.AddAlternative("text/html", "Hello html <b>pj</b>")
    

    ` This produces:

    `

    --908b4cfdd408aaeb4ad5a5525eed978aa6361f8e322bf69397de36fa21d6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

    Hello pj --908b4cfdd408aaeb4ad5a5525eed978aa6361f8e322bf69397de36fa21d6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

    Hello html pj --908b4cfdd408aaeb4ad5a5525eed978aa6361f8e322bf69397de36fa21d6-- `

    Hotmail shows the html version. Gmail shows the html version.

    opened by pjebs 12
  • anonymous relay

    anonymous relay

    Hi .

    I am trying to relay on a server with no authentication . using a telnet client , I can simply :

    1. telnet MyServer MyPort
    2. Helo
    3. MAIL FROM: [email protected]
    4. RCPT TO: [email protected]
    5. SUBJECT:how are you?
    6. period (.)

    I tried to create an Auth with Start function that returns immediately , with empty return value , or "MAIL FROM:" , but I guess no matter what I do , smtp package will go through : code, msg64, err := c.cmd(0, "AUTH %s %s", mech, resp64) that the server will decline .

    Do you have an idea for doing anonymous connection/ESMTP AUTH . my best help so far was http://www.fehcom.de/qmail/smtpauth.html

    Thanks .

    opened by guybrand 12
  • gmail login not working

    gmail login not working

    When I tried to test send an email using my gmail account I get the follow:

    panic: 534 5.7.9 Please log in with your web browser and then try again. Learn more at
    5.7.9  https://support.google.com/mail/?p=WebLoginRequired d134sm2180690ywb.23 - gsmtp
    
    opened by steviesama 11
  • Encoded headers violate RFC 2047

    Encoded headers violate RFC 2047

    Here's a small Golang program which demonstrates the problem:

    package main
    
    import (
        "gopkg.in/gomail.v2"
        "os"
    )
    
    func main() {
        m := gomail.NewMessage()
        m.SetHeader("From", "[email protected]")
        m.SetHeader("To", "[email protected]")
        m.SetHeader("Subject", "{$firstname} Bienvendio a Apostólica, aquí inicia el camino de tu")
        m.SetBody("text/plain", "Hello, World")
        m.WriteTo(os.Stdout)
    }
    

    This program will output these headers:

    Mime-Version: 1.0
    Date: Wed, 16 Mar 2016 09:08:29 -0400
    From: [email protected]
    To: [email protected]
    Subject: =?UTF-8?q?{$firstname}_Bienvendio_a_Apost=C3=B3lica,_aqu=C3=AD_inicia_el_camino_de_tu?=
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable
    

    Note that the Subject header line is 96 characters long. According to RFC 2047,

    While there is no limit to the length of a multiple-line header field, each line of a header field that contains one or more 'encoded-word's is limited to 76 characters.

    The Subject header should have been folded at 76 characters but it was not.

    opened by skyler 9
  • It will become less secure app when send to gmail

    It will become less secure app when send to gmail

    I use gmail account to send a email,but it return a error with a warning. I can fixed it by turn off some secure stuff. https://support.google.com/accounts/answer/6010255?hl=en

    Can this stuff be fixed in this library?

    opened by bronze1man 8
  • Export to []byte

    Export to []byte

    It would be nice to be able to export gomail.Message to []byte. I would suggest a function Raw() []byte on Message.

    I could implement this and make a pull request.

    opened by chrneumann 7
  • There's a way to efficiently send more than one mail in one connection?

    There's a way to efficiently send more than one mail in one connection?

    I made a quick review of your code and I think you open close a connection for each Send (https://github.com/go-gomail/gomail/blob/master/send.go#L22).

    I want to implement a job to send emails from a queue in bulk, but reusing the connection to be as more efficient as possible.

    I miss something from your API?

    Thanks!

    enhancement 
    opened by marcalj 6
  • Auth: CRAM-MD5

    Auth: CRAM-MD5

    Hi,

    as far as I understood your code you implement the smtp.Auth interface which is then used by the smtp package when calling c.Auth().

    In auth.go you implement LOGIN and PLAIN mechanisms. Have you ever thought about implementing CRAM-MD5?

    You would have to return CRAM-MD5 in Auth.Send, listen for the base64 encoded challenge in Auth.Next, decode it and return (base64 encoded) the username and a MD5 response à la

    digest = MD5(('password' XOR opad), MD5(('password' XOR ipad), challenge)).

    Details can be found in this Tutorial and RFC 2195.

    opened by Jonny007-MKD 5
  • Mail not reciving to Yahoo

    Mail not reciving to Yahoo

    Hi, I have updated the go version from 1.15 to 1.18. But while sending with version 1.18, mails not receiving to yahoo accounts. Getting the error message 5.6.7(destination does not support SMTPUTF8 required for message delivery). Working fine with version 1.15.

    opened by vindevuser 0
  • Save as .eml file

    Save as .eml file

    Is there any way to create an email and,instead of sending it with SMTP or so, saving the email on disk in .eml format so another software take care of sending it?

    Thanks

    opened by sebyno 0
  • Unnecessary problem with

    Unnecessary problem with "mail.ParseAddress(field)"

    I am developing a website and during testing I need to use fake SMTP servers, what happens is that these servers give me the credentials in this format:

    username = "29723d128c4d"
    password = "642c04628110"
    

    As you can see there is no traditional @, and when sending a mail, the function mail.ParseAddress(field) in the package gomail/send.go complains saying that there is no @, I made a fork and I have removed that function so I could use the fake SMTP, so my suggestion is to allow to disable this function, that there are two modes one for "production" and one for "development".

    gomail: could not send email 1: gomail: invalid address "29723d128c4d": mail: missing '@' or angle-addr

    opened by curiosport 0
  • Issue in assigning mail headers

    Issue in assigning mail headers

    Mail header displaying in random order, not in the order we are giving. Example:- We set headers in the following order:-

    	m.SetHeader("From", from)
    	m.SetHeader("Reply-To", replayTo)
    	m.SetHeader("To", to)
    	m.SetHeader("Subject", subject)
    

    But in the mail we got headers in the random order. Please fix this issue at the earliest.

    Thanks in advance..

    opened by amjadaliup 0
Owner
Gomail
Gomail
An easy way to send emails with attachments in Go

PROJECT DISCONTINUED This repository only exists for archival purposes. email An easy way to send emails with attachments in Go Install go get github.

Santiago Corredoira 254 May 26, 2022
Hxgomail - Gomail - a simple and efficient package to send emails

Gomail Introduction Gomail is a simple and efficient package to send emails. It

null 0 Jan 4, 2022
:white_check_mark: A Go library for email verification without sending any emails.

email-verifier ✉️ A Go library for email verification without sending any emails. Features Email Address Validation: validates if a string contains a

AfterShip Ltd. 478 Jun 26, 2022
✉️ A Go library for email verification without sending any emails.

email-verifier ✉️ A Go library for email verification without sending any emails. Features Email Address Validation: validates if a string contains a

AfterShip Ltd. 248 Jun 24, 2021
Sort the emails contained in a .csv file into a text file

Go convert csv to txt This snippet of code allows you to sort the emails contained in a .csv file into a text file.

Maxence Brochier 1 Nov 23, 2021
A simple microservice designed in Go using Echo Microframework for sending emails and/or calendar invitations to users.

Calenvite A simple microservice designed in GO using Echo Microframework for sending emails and/or calendar invitations to users. Features Send emails

Adriano Galello 12 Apr 4, 2022
Mail_sender - This library is for sending emails from your mail

Mail Sender This library is for sending emails from your mail Installation mail_

null 1 Dec 30, 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 333 Jun 26, 2022
Using Mailchain, blockchain users can now send and receive rich-media HTML messages with attachments via a blockchain address.

Mailchain Introduction Mailchain enables blockchain-based email-like messaging with plain or rich text and attachment capabilities. Using blockchain p

Mailchain 119 Jun 22, 2022
Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade

smtptest Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade All settings are configurable in the config.yaml file ser

Mario 0 Jan 6, 2022
Send markdown files as MIME-encoded electronic mail.

Send markdown files as MIME-encoded electronic mail.

Dmitry Kotik 4 May 7, 2022
Sending emails using email server talking to RabbitMQ and send grid server sending emails to email ids consumed from RabbitMQ

Sending emails using email server talking to RabbitMQ and send grid server sending emails to email ids consumed from RabbitMQ

Shivanshu Raj Shrivastava 1 Feb 9, 2022
An easy way to send emails with attachments in Go

PROJECT DISCONTINUED This repository only exists for archival purposes. email An easy way to send emails with attachments in Go Install go get github.

Santiago Corredoira 254 May 26, 2022
Node is where client will send data to, create block send to miner, create block send to parent and receive tick from validator and do validate

Node Receive Tick from validator Validate POH of tick send result to validator Receive confirm block from validator Send Checked block to validator Ho

Hieu Phan 0 Dec 31, 2021
An Alert notification service is an application which can receive alerts from certain alerting systems like System_X and System_Y and send these alerts to developers in the form of SMS and emails.

Alert-System An Alert notification service is an application which can receive alerts from certain alerting systems like System_X and System_Y and sen

null 0 Dec 10, 2021
Hxgomail - Gomail - a simple and efficient package to send emails

Gomail Introduction Gomail is a simple and efficient package to send emails. It

null 0 Jan 4, 2022
Search and store the best cryptos for the best scalable and modern application development.

Invst Hunt Search and store the best cryptos for the best scalable and modern application development. Layout Creating... Project Challenge The Techni

Fábio Morais 1 Nov 12, 2021
Eget is the best way to easily get pre-built binaries for your favorite tools.

Eget: easy pre-built binary installation Eget is the best way to easily get pre-built binaries for your favorite tools. It downloads and extracts pre-

Zachary Yedidia 288 Jun 27, 2022
:white_check_mark: A Go library for email verification without sending any emails.

email-verifier ✉️ A Go library for email verification without sending any emails. Features Email Address Validation: validates if a string contains a

AfterShip Ltd. 478 Jun 26, 2022
✉️ A Go library for email verification without sending any emails.

email-verifier ✉️ A Go library for email verification without sending any emails. Features Email Address Validation: validates if a string contains a

AfterShip Ltd. 248 Jun 24, 2021
Alerts on due products from Grocy through emails or other means.

grocy-alerts Grocy alerts was made in an attempt to give more visibility to expiring soon products in Grocy. Usage Fetch products from grocy api and c

Yann David 4 Dec 7, 2021
User enumeration and password bruteforce on Azure, ADFS, OWA, O365 and gather emails on Linkedin

goEnumBruteSpray Description Summary The recommended module is o365 for user enumeration and passwords bruteforce / spray . Additional information can

null 283 Jun 23, 2022
🕕Todo management through emails

??Todo management through emails

Changkun Ou 2 Nov 15, 2021
Sort the emails contained in a .csv file into a text file

Go convert csv to txt This snippet of code allows you to sort the emails contained in a .csv file into a text file.

Maxence Brochier 1 Nov 23, 2021
A simple microservice designed in Go using Echo Microframework for sending emails and/or calendar invitations to users.

Calenvite A simple microservice designed in GO using Echo Microframework for sending emails and/or calendar invitations to users. Features Send emails

Adriano Galello 12 Apr 4, 2022
Mail_sender - This library is for sending emails from your mail

Mail Sender This library is for sending emails from your mail Installation mail_

null 1 Dec 30, 2021
This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

echGo 5 Apr 13, 2022
skr: The lightweight and powerful web framework using the new way for Go.Another go the way.

skr Overview Introduction Documents Features Install Quickstart Releases Todo Pull Request Issues Thanks Introduction The lightweight and powerful web

go-the-way 1 Jan 11, 2022