1. Products
  2.   Email
  3.   GO
  4.   GoEmail
 
  

Open Source Go Library to Create & Send Email Messages

Free GO API for Sending Emails using SMTP Server. Create Email Messages with Attachments, Encrypt/Decrypt Messages & Embed Images with PGP/MIME.

What is GoEmail Library?

GoEmail is a simple open source GO API for sending email messages. Using the API, you can send emails using an SMTP server, but the API provides the flexibility to send an email message using local postfix. The API is lightweight and has no external dependencies when you are using Go 1.5 whereas for the API to work you need at least Go version 1.2 or greater. While using the SMPT connection, the API allows sending multiple emails using the same SMTP connection.

The API provides a bunch of features for the developers to ease the Email sending operation within GO. The developers can send SMPT emails, add attachments to emails, embed images in your message, and use HTML or text templates for generating a new email message. The API automatically encodes special characters in the message and provides support for SSL and TLS certificates.

With its clear and effective API for creating and sending email messages, the Gomail library streamlines the email sending process inside Go applications. Gomail gives you the tools you need to easily integrate email functionality into your applications, regardless of your level of experience as a developer or your level of familiarity with Go. Start integrating email sending capabilities into your Go applications today with Gomail, and streamline your communication workflows like never before.

Previous Next

Getting Started with Go-Email

The recommended way to add go-email into your project is by using GitHub. Please use the following command for a smooth installation.

Install Go-Email via GitHub

go get gopkg.in/gomail.v2

Free GO API to Send Email Messages

The open-source Go API provides an efficient way to compose email message via SMTP connection. In order to create a new email, you can create a new message instance by using NewMessage() method. The API provides different methods to set From, To, Subject and Body. In order to set From, To & Subject, you can use SetHeader() method of the API. Similary for the insert data in body of the email, you use SetBody() method of the API. Once, you have your email content ready you can open a new SMTP connection NewDialer() method by providing SMPT connection details. Once you have your connection open, the message can be delivered to the destination.

How to Compose and Send Email Message using Go API?

package main

import (
    "gopkg.in/gomail.v2"
    "log"
)

func main() {
    // Compose the email
    m := gomail.NewMessage()
    m.SetHeader("From", "your-email@example.com")
    m.SetHeader("To", "recipient@example.com")
    m.SetHeader("Subject", "Hello from Gomail!")
    m.SetBody("text/plain", "This is the plain text body.")

    // Send the email
    d := gomail.NewDialer("smtp.example.com", 587, "your-email@example.com", "your-password")
    if err := d.DialAndSend(m); err != nil {
        log.Fatal(err)
    }

    log.Println("Email sent successfully!")
}

Send Emails with Attachments via Go API?

The open source Go library offers a comprehensive suite of features for sending emails in Go applications. The library supports adding attachments and HTML content to your emails with just a couple of lines of Go commands. It enables developers to attach files to your emails effortlessly. Simply specify the path to the file, and Gomail takes care of the rest. The following simple shows how software developers can send an email message with attachments inside Go applications.

How to Send Emails with Attachments via Go API?

package main

import (
    "gopkg.in/gomail.v2"
    "log"
)

func main() {
    // Compose the email
    m := gomail.NewMessage()
    m.SetHeader("From", "sender@example.com")
    m.SetHeader("To", "recipient@example.com")
    m.SetHeader("Subject", "Email with Attachments")
    m.SetBody("text/plain", "Please find attached files.")

    // Attach files
    m.Attach("/path/to/file1.pdf")
    m.Attach("/path/to/file2.png")

    // Send the email
    d := gomail.NewDialer("smtp.example.com", 587, "your-email@example.com", "your-password")
    if err := d.DialAndSend(m); err != nil {
        log.Fatal(err)
    }

    log.Println("Email with attachments sent successfully!")
}

 English