domail

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 4 Imported by: 0

README

Domail 搞定邮件

介绍

基于gomail实现多场景封装,只需按需调用即可

支持发送文本邮件

支持发送文本带附件邮件

支持发送html邮件

支持发送html带附件邮件

支持发送邮件验证码

支持自定义函数发送邮件

安装教程
go get gitee.com/wennmu/pkg
使用说明
package main

import (
	"gitee.com/wennmu/pkg.git/domail"
	"log"
)

func main() {
	code, err := domail.SendMailCode("smtp.gmail.com", 587, "xxx@gmail.com", "***", &domail.From{Name: "每日菜菜", Addr: "xxx@gmail.com"}, []domail.Receive{{Name: "", Addr: "yyy@outlook.com"},}, "重要操作验证码", "您好,您的验证码是%s,使用后请尽快销毁。")
	if err != nil {
		log.Fatalln("err: ", err)
	}
	log.Println("code: ",code)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendHtmlMail

func SendHtmlMail(addr string, port int, username, password string, from *From, receives []Receive, subject, body string) error

发送html邮件

func SendHtmlMailWithAttach

func SendHtmlMailWithAttach(addr string, port int, username, password string, from *From, receives []Receive, subject, body, filepath string) error

发送携带附件的HTML邮件

func SendMail

func SendMail(addr string, port int, username, password string, from *From, receives []Receive, subject, body string) error

发送文本邮件

func SendMailCode

func SendMailCode(addr string, port int, username, password string, from *From, receives []Receive, subject, body string) (string, error)

发送邮件验证码 这里默认6位随机数字 body模板"您好,验证码是%s"

func SendMailWithAttach

func SendMailWithAttach(addr string, port int, username, password string, from *From, receives []Receive, subject, body, filepath string) error

发送携带附件的文本邮件

Types

type Domail

type Domail struct {
	M *gomail.Message
	D gomail.SendCloser
}

func NewDomail

func NewDomail(addr string, port int, username, password string) (*Domail, error)

func (*Domail) Send

func (s *Domail) Send() error

func (*Domail) SetAttach

func (s *Domail) SetAttach(filepath string) *Domail

func (*Domail) SetAttachWithSetting

func (s *Domail) SetAttachWithSetting(filepath string, filesetting gomail.FileSetting) *Domail

func (*Domail) SetHeader

func (s *Domail) SetHeader(from *From, to, subject string) *Domail

func (*Domail) SetHtmlBody

func (s *Domail) SetHtmlBody(body string) *Domail

func (*Domail) SetTextBody

func (s *Domail) SetTextBody(body string) *Domail

type From

type From struct {
	Name string
	Addr string
}

如果函数部分没办法满足需求,可以直接使用该部分代码

type Receive

type Receive struct {
	Name string
	Addr string
}

Jump to

Keyboard shortcuts

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