gmailer

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2020 License: MIT Imports: 7 Imported by: 0

README

gmailer

Go module that sends email using GMail OAuth.

Email envelope header shows email sent from name as the ReplyTo address, while the from address is EmailFrom:

From: reply-to@email.com <email-from@email.com>

This is useful in combination with EmailFrom set to a no-reply address.

Based on code borrowed from BinodKafle/gomail

Example usage (main.go):

package main

import (
	"fmt"
	"github.com/Presence-Web-Services/gmailer"
)

func main() {
	cfg := gmailer.Config{
		ClientID:     "YOUR_CLIENT_ID",
		ClientSecret: "YOUR_CLIENT_SECRET",
		AccessToken:  "YOUR_ACCESS_TOKEN",
		RefreshToken: "YOUR_REFRESH_TOKEN",
		EmailTo:      "email-to@email.com",
		EmailFrom:    "email-from@email.com",
		ReplyTo:      "reply-to@email.com",
		Subject:      "Test Subject",
		Body:         "This is a test email body... thanks!",
	}

	var service, err = cfg.Authenticate()
	if err != nil {
		fmt.Println("Error occurred during authenticate")
	}

	err = cfg.Send(service)
	if err != nil {
		fmt.Println("Error occurred during send")
	}
}

How to run:

go get github.com/Presence-Web-Services/gmailer
go run main.go

Documentation

Overview

Gmailer allows for OAUTH authentication to GMail and sending of basic email messages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	AccessToken  string
	RefreshToken string
	EmailTo      string
	EmailFrom    string
	ReplyTo      string
	Subject      string
	Body         string
}

Config is type containing OAuth credentials and email message information

func (*Config) Authenticate

func (config *Config) Authenticate() (gmailService *gmail.Service, err error)

Authenticate authenticates with GMail OAuth, and returns a pointer to gmail.Service when successfully authenticated

func (*Config) Send

func (config *Config) Send(gmailService *gmail.Service) (err error)

Send takes a pointer to gmail.Service and is called on a Config type to send an email

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL