github.com/admpub/mail@v0.0.0-20170408110349-d63147b0317b/smtp_test.go (about)

     1  package mail
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  func TestSend(t *testing.T) {
     9  	conf := &SMTPConfig{
    10  		Username: "swh@adm***.com",
    11  		Password: "",
    12  		Host:     "smtp.exmail.qq.com",
    13  		Port:     465,
    14  		Secure:   "SSL",
    15  	}
    16  	c := NewSMTPClient(conf)
    17  	m := NewMail()
    18  	m.AddTo("brother <1556****@qq.com>")
    19  	m.AddFrom("hank <" + conf.Username + ">")
    20  	m.AddSubject("Testing")
    21  	m.AddText("Some text :)")
    22  	filepath, _ := os.Getwd()
    23  	m.AddAttachment(filepath + "/README.md")
    24  	if e := c.Send(m); e != nil {
    25  		t.Error(e)
    26  	} else {
    27  		t.Log("发送成功")
    28  	}
    29  }