mail

package
v0.0.0-...-261bb52 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsyncSend

func AsyncSend(msg *Message, handle func(err error)) (err error)

AsyncSend is func to async send mail

Example
package main

import (
	"bytes"
	"fmt"
	"sync"

	"github.com/Cluas/gim/pkg/mail"
)

func main() {
	var wg sync.WaitGroup
	wg.Add(1)
	err := mail.AsyncSend(&mail.Message{
		Subject: "测试",
		Content: bytes.NewBufferString("<h1>你好,异步发送测试邮件内容</h1>"),
		To:      []string{"huwl@luedongtech.com"},
		//Extension: nil,
	},
		func(err error) {
			defer wg.Done()
			if err != nil {
				fmt.Println("发送邮件出现错误:", err)
			}
		})
	if err != nil {
		fmt.Printf("发送错误, %v", err)
	}
	wg.Wait()
}
Output:

func Init

func Init(c *Config) (err error)

Init provide a hook to use own config

func Send

func Send(msg *Message) (err error)

Send is func to send mail

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/Cluas/gim/pkg/mail"
)

func main() {
	err := mail.Send(&mail.Message{
		Subject: "测试",
		Content: bytes.NewBufferString("<h1>你好,同步测试邮件内容</h1>"),
		To:      []string{"huwl@luedongtech.com"},
		//Extension: nil,
	})
	if err != nil {
		fmt.Printf("发送错误, %v", err)
	}
}
Output:

Types

type Config

type Config struct {
	Addr     string
	From     string
	Password string
	StartSSL bool
}

Config is struct of sender config

type Message

type Message struct {
	Subject   string
	Content   io.Reader         // support html content
	To        []string          // to address string
	Extension map[string]string // message extension
}

Message is struct used to send msg

type SMTPSender

type SMTPSender struct {
	// contains filtered or unexported fields
}

SMTPSender used to send mail with smtp protocol

func (*SMTPSender) AsyncSend

func (s *SMTPSender) AsyncSend(msg *Message, handle func(err error)) error

AsyncSend async send mail

func (*SMTPSender) Send

func (s *SMTPSender) Send(msg *Message) (err error)

Send send mail

type Sender

type Sender interface {
	// Send send mail
	Send(msg *Message) error
	// AsyncSend async send mail need callback func
	AsyncSend(msg *Message, handle func(err error)) error
}

Sender is interface for sender

Jump to

Keyboard shortcuts

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