123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- package services
- import (
- "crypto/tls"
- "eta/eta_api/models"
- "eta/eta_api/utils"
- "fmt"
- "gopkg.in/gomail.v2"
- "strconv"
- "strings"
- )
- func SendEmailToCompany() {
- // 获取收件人列表
- //emailCond := " AND enabled = 1 "
- emailCond := ""
- emailPars := make([]interface{}, 0)
- emails, e := models.GetEnglishReportEmailList(emailCond, emailPars, "")
- if e != nil {
- fmt.Println("获取收件人列表失败, Err: " + e.Error())
- return
- }
- if len(emails) == 0 {
- fmt.Println("收件人列表为空")
- return
- }
- // TODO:这是HTML模板内容
- template := `<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,viewport-fit=cover">
- <title>Horizon Insights x Fastmarkets x FGE: 2024 Macro & Commodities Outlook - Registration Open!</title>
- </head>
- <body style="padding:0;margin:0;background-color:#fff">
- <div id="app" style="max-width:1280px;margin:0 auto;font-size:14px;min-height:100vh;">
- <div class="main-box" style="padding:25px 20px;">
- <div style="line-height:1.7;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"
- class=" __aliyun_node_has_color">
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:center;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="font-size:18.0px;font-weight:bold;font-style:normal;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;color:#000000;text-decoration:underline;"
- class=" __aliyun_node_has_color">2024 Macro & Commodities Outlook Invite</span></div>
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;color:#000000;"
- class=" __aliyun_node_has_color"><br></span></div>
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="font-style:normal;font-weight:400;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;color:#000000;"
- class=" __aliyun_node_has_color">Dear Client,</span></div>
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="font-style:normal;font-weight:400;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;color:#000000;"
- class=" __aliyun_node_has_color"><br></span></div>
- <div style="clear:both;">
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="font-style:normal;font-weight:400;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;color:#000000;"
- class=" __aliyun_node_has_color">Happy Year-End Holidays!</span></div>
- </div>
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="font-style:normal;font-weight:400;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;color:#000000;"
- class=" __aliyun_node_has_color"><br></span></div>
- <div style="clear:both;">
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;border:.0px;font-family:arial;margin:.0px;padding:.0px;outline:.0px;font-size:13.0px;"
- class=" __aliyun_node_has_color">As we usher in the new year, Horizon Insights, in collaboration
- with Fastmarkets and FGE, is proud to announce</span><span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;font-family:arial;font-size:13.0px;"
- class=" __aliyun_node_has_color"> our 2024 Macro & Commodities Outlook which will be
- held </span><span
- style="font-weight:bold;color:#000000;font-style:normal;text-transform:none;font-family:arial;font-size:13.0px;text-decoration:none;"
- class=" __aliyun_node_has_color">virtually</span><span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;font-family:arial;font-size:13.0px;text-decoration:none;"
- class=" __aliyun_node_has_color"> on </span><span
- style="font-weight:bold;color:#000000;font-style:normal;text-transform:none;font-family:arial;font-size:13.0px;text-decoration:none;"
- class=" __aliyun_node_has_color">10 & 11 Jan 2024</span><span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;font-family:arial;font-size:13.0px;"
- class=" __aliyun_node_has_color">, </span><span
- style="color:#000000;font-family:arial;font-size:13.0px;font-style:normal;font-weight:bold;text-transform:none;"
- class=" __aliyun_node_has_color">5pm - 8pm SGT</span><span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;font-family:arial;font-size:13.0px;"
- class=" __aliyun_node_has_color"> (i.e. </span><span
- style="color:#000000;font-family:arial;font-size:13.0px;font-style:normal;font-weight:bold;text-transform:none;"
- class=" __aliyun_node_has_color">9am - 12pm BST</span><span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;font-family:arial;font-size:13.0px;"
- class=" __aliyun_node_has_color">). Our experienced analysts from Horizon Insights together with
- guest speakers from our valued partners will present our views in the fields of Macro, Ferrous
- Metals, Base Metals, Energy, as well as Petrochemicals.</span></div>
- </div>
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-size:13.0px;font-family:arial;"><br></span>
- </div>
- <div style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-size:13.0px;font-family:arial;">Please
- see below for our event schedule:</span></div>
- <div
- style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;">
- <br></div>
- <div
- style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;">
- <span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-size:13.0px;font-family:arial;"
- class=" __aliyun_node_has_color"> <img style="vertical-align: bottom; margin: 0px;"
- height="3301"
- src="https://hzstatic.hzinsights.com/static/images/202312/20231228/KeDTAxIZ3UrZR5DZKKIQLdoIaOVB.png"
- width="890"></span></div>
- <div
- style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;">
- <span
- style="color:#000000;font-style:normal;font-weight:400;text-transform:none;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-size:13.0px;font-family:arial;"
- class=" __aliyun_node_has_color"> </span></div>
- <div
- style="clear:both;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-indent:.0px;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;">
- <br></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;"><br></span>
- </div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;">To
- register, simply scan the QR code in the posters above to indicate your interest. Alternatively, you
- may also </span><span
- style="font-weight:bold;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;"><a
- href="https://forms.gle/yhPRDcri43P2QyPt8" target="_blank">register here</a></span><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;">.</span>
- </div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;color:#000000;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline;"
- class=" __aliyun_node_has_color">Should you encounter any difficulties registering, please contact
- Stephanie (stephanie@hzinsights.com).</span></div>
- <div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="font-weight:bold;margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;">The
- virtual meeting details will be disseminated to you a few days prior to the event.</span></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><br></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;">Lastly,
- our firm would like to wish all of you a prosperous Happy New Year! We look forward to seeing
- everyone on the 10th & 11th.</span></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;"><br></span>
- </div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;clear:both;"
- class=" __aliyun_node_has_color"><span
- style="margin:.0px;padding:.0px;border:.0px;outline:.0px;font-family:arial;font-size:13.0px;">Cheers!</span>
- </div>
- </div>
- <div><br></div>
- <div>
- <div style="clear:both;"><span style="font-family:arial;font-size:13.0px;color:#000000;"
- class=" __aliyun_node_has_color"><br></span></div>
- <div style="clear:both;">
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;clear:both;font-variant-caps:normal;text-align:start;text-indent:.0px;"
- class="x___aliyun_node_has_color"><br></div>
- <div style="margin:.0px;padding:.0px;border:.0px;outline:.0px;clear:both;font-variant-caps:normal;text-align:start;text-indent:.0px;"
- class="x___aliyun_node_has_color"></div>
- </div>
- </div>
- <div><br></div>
- <div><br></div>
- <div><br></div>
- <div style="line-height:20.0px;clear:both;"><br></div>
- </div>
- </div>
- </div>
- </body>
- </html>`
- // 推送信息
- sendData := make([]*EnglishReportSendEmailRequest, 0)
- for i := range emails {
- r := new(EnglishReportSendEmailRequest)
- r.EmailId = emails[i].Id
- r.Email = strings.Replace(emails[i].Email, " ", "", -1)
- r.Subject = "Horizon Insights x Fastmarkets x FGE: 2024 Macro & Commodities Outlook - Registration Open!" // TODO:这是主题
- r.FromAlias = "Horizon FICC" // TODO:这是推送人(中文)
- r.HtmlBody = template
- sendData = append(sendData, r)
- }
- if len(sendData) == 0 {
- fmt.Println("无邮件可推送")
- return
- }
- // 请求阿里云接口批量推送
- aliEmail := new(AliyunEmail)
- resultList, e := aliEmail.BatchSendEmail(sendData)
- if e != nil {
- fmt.Println("批量推送失败, Err: " + e.Error())
- return
- }
- for _, r := range resultList {
- utils.FileLog.Info("email: %s, ok: %v, res: %s", r.Email, r.Ok, r.ResultData)
- if r.Ok {
- fmt.Println("发送成功")
- } else {
- fmt.Println("发送失败:" + r.ResultData)
- }
- }
- }
- type SendEmailReq struct {
- Title string `description:"标题"`
- Content string `description:"内容"`
- ToUser []string `description:"收信人邮箱"`
- }
- func SendEmail(req SendEmailReq) (success bool, err error) {
- if req.Title == "" {
- err = fmt.Errorf("邮件主题不可为空")
- return
- }
- if req.Content == "" {
- err = fmt.Errorf("邮件内容不可为空")
- return
- }
- if len(req.ToUser) <= 0 {
- err = fmt.Errorf("收信人不可为空")
- return
- }
- // 邮箱配置
- confMap, e := models.GetBusinessConf()
- if e != nil {
- err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
- return
- }
- checkArr := []string{
- models.BusinessConfEmailServerHost, models.BusinessConfEmailServerPort,
- models.BusinessConfEmailSender, models.BusinessConfEmailSenderUserName,
- models.BusinessConfEmailSenderPassword,
- }
- for _, v := range checkArr {
- if confMap[v] == "" {
- err = fmt.Errorf("%s配置有误", v)
- return
- }
- }
- port, _ := strconv.Atoi(confMap[models.BusinessConfEmailServerPort])
- if port <= 0 {
- port = 587 // 默认587端口
- }
- m := gomail.NewMessage()
- m.SetHeader("From", confMap[models.BusinessConfEmailSender])
- m.SetHeader("To", req.ToUser...)
- m.SetHeader("Subject", req.Title)
- m.SetBody("text/html", req.Content)
- d := gomail.NewDialer(confMap[models.BusinessConfEmailServerHost], port, confMap[models.BusinessConfEmailSenderUserName], confMap[models.BusinessConfEmailSenderPassword])
- // 解决x509报错的问题。证书不通过。跳过证书验证
- config := &tls.Config{ServerName: confMap[models.BusinessConfEmailServerHost], InsecureSkipVerify: true}
- d.TLSConfig = config
- if e = d.DialAndSend(m); e != nil {
- err = fmt.Errorf("邮件发送失败, Err: %s", e.Error())
- return
- }
- success = true
- return
- }
|