gomail发送附件

采用github.com/go-gomail/gomail/ 的邮件功能,可以发送附件 以及html文档,下面是其给出的demo,测试通过。

 

package main



//cmd:  go get gopkg.in/gomail.v1



import (

    "gopkg.in/gomail.v1"

)



func main() {

    msg := gomail.NewMessage()

    msg.SetHeader("From", "[email protected]")

    msg.SetHeader("To", "[email protected]", "[email protected]")

    //msg.SetAddressHeader("Cc", "[email protected]", "Dan")

    msg.SetHeader("Subject", "Hello!")

    msg.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")



    f, err := gomail.OpenFile("C:/Documents and Settings/yan/My Documents/My Pictures/old/bg.jpg")

    if err != nil {

        panic(err)

    }

    msg.Attach(f)



    //smtp.163.com:25

    mailer := gomail.NewMailer("smtp.163.com", "[email protected]", "xxxxxxx", 25)

    if err := mailer.Send(msg); err != nil {

        panic(err)

    }

}

 

你可能感兴趣的:(mail)