forked from lanyulei/ferry
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
192 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package email | ||
|
||
/* | ||
@Author : lanyulei | ||
@Desc : 发送邮件 | ||
*/ | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/spf13/viper" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/gomail.v2" | ||
) | ||
|
||
func server(mailTo []string, subject, body string, args ...string) error { | ||
//定义邮箱服务器连接信息,如果是网易邮箱 pass填密码,qq邮箱填授权码 | ||
mailConn := map[string]string{ | ||
"user": viper.GetString("settings.email.user"), | ||
"pass": viper.GetString("settings.email.pass"), | ||
"host": viper.GetString("settings.email.host"), | ||
"port": viper.GetString("settings.email.port"), | ||
} | ||
|
||
port, _ := strconv.Atoi(mailConn["port"]) //转换端口类型为int | ||
|
||
m := gomail.NewMessage() | ||
|
||
m.SetHeader("From", m.FormatAddress(mailConn["user"], viper.GetString("settings.email.alias"))) //这种方式可以添加别名,即“XX官方” | ||
m.SetHeader("To", mailTo...) //发送给多个用户 | ||
m.SetHeader("Subject", subject) //设置邮件主题 | ||
m.SetBody("text/html", body) //设置邮件正文 | ||
|
||
d := gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"]) | ||
err := d.DialAndSend(m) | ||
return err | ||
|
||
} | ||
|
||
func SendMail(mailTo []string, subject, body string) { | ||
err := server(mailTo, subject, body) | ||
if err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
log.Println("send successfully") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package notify | ||
|
||
import ( | ||
"ferry/models/system" | ||
"ferry/pkg/notify/email" | ||
) | ||
|
||
/* | ||
@Author : lanyulei | ||
@同时发送多种通知方式 | ||
*/ | ||
|
||
func SendNotify(classify []int, sendTo interface{}, subject, body string) { | ||
var ( | ||
emailList []string | ||
) | ||
for _, c := range classify { | ||
switch c { | ||
case 1: // 邮件 | ||
for _, user := range sendTo.(map[string]interface{})["userList"].([]system.SysUser) { | ||
emailList = append(emailList, user.Email) | ||
} | ||
go email.SendMail(emailList, subject, body) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters