sendmail.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package sendmail
  2. import (
  3. "go-common/app/tool/saga/model"
  4. "go-common/app/tool/saga/service/mail"
  5. "go-common/library/log"
  6. )
  7. /*
  8. mail model:
  9. 【Saga 提醒】+mailTitle
  10. Saga 事件通知
  11. 执行状态 : 成功
  12. Pipeline信息: http://gitlab.bilibili.co/platform/go-common/pipelines/1551
  13. 来源分支 : ci-commit/test
  14. 修改说明 :
  15. 额外信息: 你真是棒棒的,合并成功了
  16. */
  17. func SendMail(sendTo []string, url string, data string, sourceBranch string, extraData string, pipeStatus string) {
  18. var (
  19. mAddress model.Mail
  20. mDada model.MailData
  21. )
  22. for _, to := range sendTo {
  23. singleMail := &model.MailAddress{Address: to}
  24. mAddress.ToAddress = append(mAddress.ToAddress, singleMail)
  25. }
  26. if pipeStatus == "failed" {
  27. mAddress.Subject = "【Saga 提醒】Pipeline 执行失败 "
  28. mDada.PipeStatus = "失败"
  29. } else if pipeStatus == "success" {
  30. mAddress.Subject = "【Saga 提醒】Pipeline 执行成功 "
  31. mDada.PipeStatus = "成功"
  32. } else {
  33. mAddress.Subject = "【Saga 提醒】 " + pipeStatus
  34. }
  35. mDada.Info = extraData
  36. mDada.Description = data
  37. mDada.SourceBranch = sourceBranch
  38. mDada.URL = url
  39. mDada.PipelineStatus = pipeStatus
  40. if err := mail.SendMail3("saga@bilibili.com", "SAGA", "Lexgm8AAQrF7CcNA", &mAddress, &mDada); err != nil {
  41. log.Error("Error(%v)", err)
  42. }
  43. }