Skip to content

A simple smtp mail scheduler build by gomail and cron.

Notifications You must be signed in to change notification settings

AmbitiousJun/go-mailscheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-mailscheduler

A simple smtp mail scheduler build by gomail and cron.

Install

go get -u github.com/AmbitiousJun/[email protected]

Usage

sOpt := mailscheduler.SmtpOptions{
    Host:       "smtp.qq.com",
    Port:       587,
    Username:   "[email protected]",
    Credential: "your credential",
}
mOpt := mailscheduler.MailOptions{
    From:     "[email protected]",
    To:       []string{"[email protected]", "[email protected]"},
    Subject:  "Test Subject",
    // Use text/html mail body
    BodyType: mailscheduler.MailBodyHtml,
    BodyBuildFunc: func() (string, error) {
        return "<html><body><h1>Hello World</h1></body></html>", nil
    },
    FallbackBodyBuildFunc: func() string {
        return "<html><body><h1>This is a fallback mail</h1></body></html>"
    },
}

// Send mail every 2 minutes
ms, err := mailscheduler.New("*/2 * * * *", &mOpt, &sOpt)
if err != nil {
    t.Error(err)
    return
}

// Send normal mail manually
ms.Send(false)

// Send fallback mail manually
ms.Send(true)

// Start scheduler
ms.Start()

// Wait 3 minutes
<-time.After(time.Minute * 3)

ms.Stop()
log.Println("scheduler stop.")

About

A simple smtp mail scheduler build by gomail and cron.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages