You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
926 B

2 months ago
package service
import (
"context"
"github.com/jordan-wright/email"
"log"
"net/smtp"
"tyj_admin/api/v1/system"
)
type IEmail interface {
SendEmail(ctx context.Context, req *system.SendEmailReq) (res *system.SendEmailRes, err error)
}
type emailServiceTmpl struct {
}
var emailService = emailServiceTmpl{}
func Email() IEmail {
return &emailService
}
/*
* Description:
*
* 使用凭据初始化账号Client
* @return Client
* @throws Exception
*/
func (a *emailServiceTmpl) SendEmail(ctx context.Context, req *system.SendEmailReq) (res *system.SendEmailRes, err error) {
e := email.NewEmail()
e.From = "lin <13950405063@163.com>"
e.To = []string{"349589071@qq.com"}
e.Subject = "Awesome web"
e.Text = []byte("Text Body is, of course, supported!")
err = e.Send("smtp.163.com:25", smtp.PlainAuth("", "linquan13950405063@163.com", "lin_quan120", "smtp.163.com"))
if err != nil {
log.Fatal(err)
}
return
}