sendcommonmaillogic.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/mail"
  4. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  5. "context"
  6. "fmt"
  7. "time"
  8. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
  9. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type SendCommonMailLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewSendCommonMailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendCommonMailLogic {
  18. return &SendCommonMailLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *SendCommonMailLogic) SendCommonMail(in *pb.SendMailReq) (*pb.BiReply, error) {
  25. for k, v := range entity.GmailAuth {
  26. fool := mail.GSendMail_q("剑鱼标讯", in.Mails, "", "", in.Title, in.Content, "", "", v)
  27. if fool {
  28. logx.Info(in.Mails, fmt.Sprintf("使用%s发送邮件成功", v.User))
  29. break
  30. }
  31. if k < len(entity.GmailAuth)-1 {
  32. logx.Info(in.Mails, fmt.Sprintf("使用%s发送邮件失败!3s后使用其他邮箱尝试", v.User))
  33. } else {
  34. logx.Info(in.Mails, fmt.Sprintf("使用%s发送邮件失败!", v.User))
  35. }
  36. time.Sleep(time.Second * 3)
  37. }
  38. return &pb.BiReply{
  39. ErrorCode: 0,
  40. ErrorMsg: "发送成功",
  41. Data: nil,
  42. }, nil
  43. }