gosim

package module
v0.0.0-...-478a4e8 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 2 Imported by: 0

README

gosim

Gosim(Go + Simple + Mailer)

Dead simple email client for Go

Get started

Add the package

go get github.com/michaelgrigoryan25/gosim

Then, just include it in your code like this

import (
    "github.com/michaelgrigoryan25/gosim"
)

Quickstart

To send emails with Gosim you will need several things:

  • SMTP host
  • SMTP port
  • SMTP username
  • SMTP password
Client

Struct Client is the SMTP client that is used to send the emails

type Client struct {
	Host string
	User string
	Pass string
	Port string
}
Message

Sturct Message provides a really easy way to construct an email

type Message struct {
	Subject string
	Message string
	From    string
	Type    ContentType
	To      []string
}
Content Type

Enum ContentType is used to specify the Content-Type header of the email

type ContentType string
const (
	Html ContentType = "HTML"
	Text ContentType = "TEXT"
)

Examples

Here's a complete example to get you started with Gosim

package main

import (
	"github.com/michaelgrigoryan25/gosim"
)

func main() {
	client := gosim.Client{
		Port: "smtp-port",
        Host: "smtp.domain.com",
		User: "email@domain.com",
		Pass: "some-random-password",
	}

	message := gosim.Message{
		Subject: "Hello World",
		To: []string{
			"user1@domain.com",
			"user2@domain.com",
		},
		From:    "email@domain.com",
		Message: "This is my message sent from Gosim",
	}

	err := client.SendFunc(&message)
	if err != nil {
		fmt.Println("Failed to send the email")
	}

	fmt.Println("Sent the email successfully")
}

Contributions

This project is open to any suggestions, contributions, issues and pull-requests!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host string
	User string
	Pass string
	Port string
}

func (*Client) SendFunc

func (c *Client) SendFunc(m *Message) error

Function for sending emails

type ContentType

type ContentType string
const (
	Html ContentType = "HTML"
	Text ContentType = "TEXT"
)

type Message

type Message struct {
	Subject string
	Message string
	From    string
	Type    ContentType
	To      []string
}

Jump to

Keyboard shortcuts

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