Giter Site home page Giter Site logo

smtp2go-go's Introduction

Crates.io Build Status license

SMTP2GO API

Go wrapper around the SMTP2GO /email/send API endpoint.

Installation

go get github.com/smtp2go-oss/smtp2go-go

Add the import in your source file

import "github.com/smtp2go-oss/smtp2go-go"

Usage

Sign up for a free account here and once logged in navigate to the Settings -> Api Keys page, create a new API key and make sure the /email/send endpoint is enabled:

Once you have an API key you need to export it into the environment where your Go application is going to be executed, this can be done on the terminal like so:

`$ export SMTP2GO_API_KEY="<your_API_key>"`

Or alternatively you can set it in code via

import "os"
os.Setenv("SMTP2GO_API_KEY", "<your_API_key>")

Then sending mail is as simple as:

package main

import (
	"fmt"
	"github.com/smtp2go-oss/smtp2go-go"
)

func main() {

	email := smtp2go.Email{
		From: "Matt <[email protected]>",
		To: []string{
			"Dave <[email protected]>",
		},
		Subject:  "Trying out SMTP2GO",
		TextBody: "Test Message",
		HtmlBody: "<h1>Test Message</h1>",
	}
	res, err := smtp2go.Send(&email)
	if err != nil {
		fmt.Println("An Error Occurred: %s", err)
	}
	fmt.Println("Sent Successfully: %s", res)
}

You can also send Asynchronously:

package main

import (
	"fmt"
	"github.com/smtp2go-oss/smtp2go-go"
)

func main() {

	email := smtp2go.Email{
		From: "Matt <[email protected]>",
		To: []string{
			"Dave <[email protected]>",
		},
		Subject:  "Trying out SMTP2GO",
		TextBody: "Test Message",
		HtmlBody: "<h1>Test Message</h1>",
	}

	var c chan *smtp2go.SendAsyncResult = smtp2go.SendAsync(&email)
	res := <-c
	if res.Error != nil {
		fmt.Println("An Error Occurred: %s", res.Error)
	}
	fmt.Println("Sent Successfully: %s", res.Result)
}

Development

Clone repo. Run tests with go test.

Contributing

Bug reports and pull requests are welcome on GitHub here

License

The package is available as open source under the terms of the MIT License.

smtp2go-go's People

Contributors

matthewljsmith avatar corymb avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.