go gomail

package main

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

import (
    "gopkg.in/gomail.v1"
)

func main() {
    msg := gomail.NewMessage()
    msg.SetHeader("From", "xxx@163.com")
    msg.SetHeader("To", "zzzzzzz@qq.com", "xxx@163.com")
    //msg.SetAddressHeader("Cc", "dan@example.com", "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", "xxx@163.com", "xxxxxxx", 25)
    if err := mailer.Send(msg); err != nil {
        panic(err)
    }
}

 

posted on 2016-04-21 15:03  rojas  阅读(224)  评论(0编辑  收藏  举报