mail

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 10 Imported by: 0

README

noknow-hub/pkg-go/mail

Getting Started

Import
import (
    "github.com/noknow-hub/pkg-go/mail"
)

Usage

Basic usage
host := "your.samtp.server"
port := 465
fromEmail := "from@example.com"
fromName := "Service"
toEmail := "to@example.com"
subject := "[Subject] Test email"
authName := "auth_user"
authPass := "auth_pass"

smtpClient := mail.NewSmtpClient(host, port, fromEmail, toEmail, subject).
    SetFromName(fromName).
    SetAuthPlain(authName, authPass, host).
    SetTlsConfig(host)

// Text body.


if err := smtpClient.Send(); err != nil {
    // Error handling.
}

Documentation

Overview

//////////////////////////////////////////////////////////////////// mail.go ////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////// smtp_client.go ////////////////////////////////////////////////////////////////////

Index

Constants

View Source
const (
	CHARSET_ISO_2022_JP          = "iso-2022-jp"
	CHARSET_US_ASCII             = "us-ascii"
	CHARSET_UTF8                 = "UTF-8"
	CONTENT_TYPE_TEXT_HTML       = "text/html"
	CONTENT_TYPE_TEXT_PLAIN      = "text/plain"
	CONTENT_TYPE_TEXT_RICHTEXT   = "text/richtext"
	CONTENT_TYPE_TEXT_X_WHATEVER = "text/x-whatever"
	MIME_VERSION_1_0             = "1.0"
)

Variables

This section is empty.

Functions

func SetFuncMapSafeHtml

func SetFuncMapSafeHtml(f template.FuncMap)

//////////////////////////////////////////////////////////////////// Set funcMap for SafeHtml. ////////////////////////////////////////////////////////////////////

Types

type Attachment

type Attachment struct {
	Base64EncodedData string
	ContentType       string
	FileName          string
}

type AuthConfig

type AuthConfig struct {
	Crammd5Auth *CRAMMD5Auth
	PlainAuth   *PlainAuth
}

type Body

type Body struct {
	ContentType string
	Charset     string
	Data        string
}

type CRAMMD5Auth

type CRAMMD5Auth struct {
	UserName string
	Secret   string
}

type PlainAuth

type PlainAuth struct {
	UserName string
	Password string
	Host     string
}

type SmtpClient

type SmtpClient struct {
	Attachments []*Attachment
	AuthConfig  *AuthConfig
	Bcc         []string
	BodyHtml    *Body
	BodyText    *Body
	Cc          []string
	FromEmail   string
	FromName    string
	Host        string
	MimeVersion string
	Port        int
	Rcpts       []string
	Subject     string
	TlsConfig   *tls.Config
	To          []string
}

func NewSmtpClient

func NewSmtpClient(host string, port int, fromEmail, toEmail, subject string) *SmtpClient

//////////////////////////////////////////////////////////////////// New SmtpClient. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) AppendAttachment

func (c *SmtpClient) AppendAttachment(base64EncodedData, contentType, fileName string) *SmtpClient

//////////////////////////////////////////////////////////////////// Append an attachment. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) AppendBcc

func (c *SmtpClient) AppendBcc(bcc string) *SmtpClient

//////////////////////////////////////////////////////////////////// Append an email into bcc. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) AppendCc

func (c *SmtpClient) AppendCc(cc string) *SmtpClient

//////////////////////////////////////////////////////////////////// Append an email into cc. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) AppendTo

func (c *SmtpClient) AppendTo(to string) *SmtpClient

//////////////////////////////////////////////////////////////////// Append an email into to. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) Send

func (c *SmtpClient) Send() error

//////////////////////////////////////////////////////////////////// Send Email ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetAuthCramMd5

func (c *SmtpClient) SetAuthCramMd5(userName, secret string) *SmtpClient

//////////////////////////////////////////////////////////////////// Set SMTP auth for CRAM-MD5. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetAuthPlain

func (c *SmtpClient) SetAuthPlain(userName, password, host string) *SmtpClient

//////////////////////////////////////////////////////////////////// Set SMTP auth for PLAIN. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetBodyHtmlFromFiles

func (c *SmtpClient) SetBodyHtmlFromFiles(charset string, fileNames []string, params map[string]interface{}, funcMap template.FuncMap) error

//////////////////////////////////////////////////////////////////// Set SMTP body HTML from files. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetBodyHtmlFromStr

func (c *SmtpClient) SetBodyHtmlFromStr(charset string, text string, params map[string]interface{}, funcMap template.FuncMap) error

//////////////////////////////////////////////////////////////////// Set SMTP body HTML from string. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetBodyTextFromFiles

func (c *SmtpClient) SetBodyTextFromFiles(charset string, fileNames []string, params map[string]interface{}, funcMap template.FuncMap) error

//////////////////////////////////////////////////////////////////// Set SMTP body text from files. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetBodyTextFromStr

func (c *SmtpClient) SetBodyTextFromStr(charset string, text string, params map[string]interface{}, funcMap template.FuncMap) error

//////////////////////////////////////////////////////////////////// Set SMTP body text from string. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetCertBytes

func (c *SmtpClient) SetCertBytes(certPem []byte, keyPem []byte) error

//////////////////////////////////////////////////////////////////// Set certificate bytes into the TLS config. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetCertFiles

func (c *SmtpClient) SetCertFiles(certFile string, keyFile string) error

//////////////////////////////////////////////////////////////////// Set certificate files into the TLS config. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetFromName

func (c *SmtpClient) SetFromName(name string) *SmtpClient

//////////////////////////////////////////////////////////////////// Set SMTP from name. ////////////////////////////////////////////////////////////////////

func (*SmtpClient) SetTlsConfig

func (c *SmtpClient) SetTlsConfig(serverName string) *SmtpClient

//////////////////////////////////////////////////////////////////// Set SMTP TLS. ////////////////////////////////////////////////////////////////////

Jump to

Keyboard shortcuts

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