mail

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 4 Imported by: 0

README

Go Email Package

Simple send email package for Go.

Installation


go get github.com/root27/go-mail

Functions

  • Send Email with text

This function only sends text emails. You can find usage and details of the function below.


func Send(host string, from string, passKey string, to string, subject string, body string) error

Example

package main

import (
    "fmt"
    "github.com/root27/go-mail"
)
func main(){
	host := "HOST NAME" // e.g gmail, yandex

	from := "MAIL ADDRESS FROM WHICH YOU WILL SEND"

	to := "MAIL ADDRESS TO WHICH YOU WILL SEND"

	//PASSKEY IS THE KEY OF THE MAIL ADDRESS FROM WHICH YOU WILL SEND

	subject := "test"

	message := "Hello World"

	err := mail.Send(host, from, "YOUR PASSKEY", to, subject, message)

	if err != nil {
		panic(err)
	}

	fmt.Println("Mail sent successfully")

}

  • Send Email with html template

This function sends html emails. You can find usage and details of the function below.


func SendWithHtml(host string, from string, passKey string, to string, subject string, htmlTemplate string) error

Example

package main

import (
	"fmt"

	mail "github.com/root27/go-mail"
)

func main() {

	host := "HOST NAME" // e.g gmail, yandex

	from := "MAIL ADDRESS FROM WHICH YOU WILL SEND"

	to := "MAIL ADDRESS TO WHICH YOU WILL SEND"

	//PASSKEY IS THE KEY OF THE MAIL ADDRESS FROM WHICH YOU WILL SEND

	subject := "Html test"

	htmlPath := "Path of the html file"

	err := mail.SendWithHtml(host, from, "YOUR PASSKEY", to, subject, htmlPath)

	if err != nil {
		panic(err)
	}

	fmt.Println("Mail sent successfully")

}

  • Send Email with html template and variables

This function sends html emails with variables. If you have any variables in your html template, you can use this function. You can find usage and details of the function below.


func SendHtmlWithVariables(host string, from string, passKey string, to string, subject string, htmlTemplate string, variables interface{}) error

Example

package main

import (
	"log"

	"github.com/root27/go-mail"
)

func main() {

	host := "HOST NAME" // e.g gmail, yandex

	from := "MAIL ADDRESS FROM WHICH YOU WILL SEND"

	to := "MAIL ADDRESS TO WHICH YOU WILL SEND"

	//PASSKEY IS THE KEY OF THE MAIL ADDRESS FROM WHICH YOU WILL SEND

	subject := "Variable Test"


	htmlPath := "Path of the html file"

	data := struct {
		Name string
		Age  int
	}{
		Name: "Oğuzhan",
		Age:  21,
	}

	err := mail.SendHtmlWithVariables(host, from, "YOUR PASSKEY", to, subject, htmlPath, data)

	if err != nil {
		panic(err)
	}

	log.Printf("Mail sent successfully")

}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(host string, from string, passKey string, to string, subject string, body string) error

func SendHtmlWithVariables

func SendHtmlWithVariables(host string, from string, passKey string, to string, subject string, temp string, variables interface{}) error

func SendWithHtml

func SendWithHtml(host string, from string, passKey string, to string, subject string, temp string) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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