gosmtp

package module
v0.0.0-...-ba1c8d5 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 12 Imported by: 0

README

GoSMTP

Installation

go get -u -v gitee.com/symowl/gosmtp

Usage

package main

import (
    "fmt"
    "net/smtp"

    "gitee.com/symowl/gosmtp"
)

func main() {
    email := gosmtp.NewEmail("mail.example.com:25")
    email.SetFrom("from@example.com", "")
    email.AddTo("to@example.com", "")
    email.SetSubject("Example E-Mail", false, false)
    email.SetPlain([]string{"123", "456"})
    auth := gosmtp.UnencryptedAuth("", "username", "password", email.GetHost())
    fmt.Println(smtp.SendMail(email.Addr, auth, email.GetFrom(), email.GetTo(), email.GetMessage()))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnencryptedAuth

func UnencryptedAuth(identity, username, password, host string) smtp.Auth

UnencryptedAuth returns an Auth that implements the PLAIN authentication mechanism as defined in RFC 4616. The returned Auth uses the given username and password to authenticate to host and act as identity. Usually identity should be the empty string, to act as username.

Types

type Email

type Email struct {
	Addr string
	// contains filtered or unexported fields
}

Email records information about an email.

func NewEmail

func NewEmail(addr string) Email

NewEmail returns an empty e-mail data. The incoming parameter is a string of "host:port".

func (*Email) AddAttachment

func (m *Email) AddAttachment(filename string) error

AddAttachment adds an e-mail attachment. The incoming parameter is a string describing the location of the file. The return value contains error information.

func (*Email) AddBcc

func (m *Email) AddBcc(address string, name string)

AddBcc adds an e-mail blind carbon copy.

func (*Email) AddCc

func (m *Email) AddCc(address string, name string)

AddCc adds an e-mail carbon copy.

func (*Email) AddTo

func (m *Email) AddTo(address string, name string)

AddTo adds an e-mail recipient.

func (*Email) GetFrom

func (m *Email) GetFrom() string

GetFrom gets the sender of the mail.

func (*Email) GetHost

func (m *Email) GetHost() string

GetHost gets the host name of the mail server.

func (*Email) GetMessage

func (m *Email) GetMessage() []byte

GetMessage gets the body content of the mail.

func (*Email) GetTo

func (m *Email) GetTo() []string

GetTo gets the recipients of mail, including To, Cc, Bcc.

func (*Email) SetFrom

func (m *Email) SetFrom(address string, name string)

SetFrom sets the e-mail sender.

func (*Email) SetHTML

func (m *Email) SetHTML(str string)

SetHTML sets the e-mail content to html. The incoming parameter is an HTML format string.

func (*Email) SetPlain

func (m *Email) SetPlain(str []string)

SetPlain sets the e-mail content to plain text. The incoming parameter is an array of strings. To describe the contents of each line.

func (*Email) SetSubject

func (m *Email) SetSubject(subject string, forward bool, reply bool)

SetSubject sets the e-mail subject.

Jump to

Keyboard shortcuts

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