Exemplo n.º 1
0
        public ApiResponse SendLeadAutoReply(LeadToSendAutoEmailModel data, UserProfile user, string apiKey = "", string tokenJson = "")
        {
            data.MergeVariants();
            //hệ thống
            if (data.SendFromType == 0)
            {
                _replyMail = new MailAddress(data.ReplyTo, data.SendName);
                GmailSvc svc = new GmailSvc(EmailSendType.Lead_AutoReply, _replyMail.DisplayName);
                var      res = svc.SendMail(data.Title, data.BodyHtml, new MailAddress(data.Email, data.FullName), _replyMail);
                return(res);
            }
            else // cá nhân
            {
                data.ToIntegrationEmail();

                Random rnd  = new Random();
                int    idx  = data.FromEmailList.Count > 0? rnd.Next(0, data.FromEmailList.Count - 1):0;
                var    u    = data.FromEmailList[idx];
                var    from = new MailAddress(u.Email, u.Name);

                GmailPersonalSvc svc = new GmailPersonalSvc(apiKey, tokenJson);
                var res = svc.SendMail(data.Title, data.BodyHtml, new MailAddress(data.Email, data.FullName), from);
                if (res.Code != System.Net.HttpStatusCode.OK)
                {
                    string content = $"Kiểm tra lại tích hợp gmail của email {u.Email} trên punnel của bạn còn hiệu lực gửi email không";
                    new EmailUtils(new EmailToModel()
                    {
                        Email     = user.Email,
                        FullName  = user.FullName,
                        AvatarUrl = user.Avatar
                    }).SendNotify_AutoReplyError(content);
                }
                return(res);
            }
        }
Exemplo n.º 2
0
        public ApiResponse SendAutomation(LeadToSendAutoEmailModel data)
        {
            var profile = uow.UserProfile.Get(data.UserId);
            var r       = new ApiResponse();

            switch (data.Type)
            {
            case 1:
                string apiKey = "", tokenJson = "";
                if (data.SendFromType == 1)
                {
                    data.ToIntegrationEmail();
                    var apiSite = uow.Integration.GetByAccId(data.UserId, (int)IntegrationType.Gmail, data.FromEmailList[0].Email);  // _dbSet.AsNoTracking().FirstOrDefault(x => x.UserId == userId && x.AccId == accId);
                    if (apiSite != null)
                    {
                        apiKey    = apiSite.ApiKey;
                        tokenJson = apiSite.TokenJson;
                    }
                }
                _log.ErrorFormat("Send email token Json:{0}", tokenJson);
                r = new Utils.EmailUtils().SendLeadAutoReply(data, profile, apiKey, tokenJson);
                break;

            case 2:
                r = new SmsService().SendLeadAutoReply(data, profile);
                break;
            }
            return(r);
        }
Exemplo n.º 3
0
        public ApiResponse SendLeadAutoReply(LeadToSendAutoEmailModel data, UserProfile user)
        {
            var res = new ApiResponse();

            try
            {
                data.MergeVariants();
                if (data.SendFromType == 0)
                {
                    var content = ProcessSmsContent(data.BodyHtml);
                    var r       = Send(data.Phone, content);
                    res.Code = r == true ? HttpStatusCode.OK : HttpStatusCode.BadRequest;
                }
                else
                {
                    var content = ProcessSmsContent(data.BodyHtml);
                    data.ToIntegrationSms();

                    Random rnd  = new Random();
                    int    idx  = data.FromSmsList.Count > 0 ? rnd.Next(0, data.FromSmsList.Count - 1) : 0;
                    var    u    = data.FromSmsList[idx];
                    var    sim  = u.Sim1;
                    string tsim = "sim1";
                    if (string.IsNullOrEmpty(sim))
                    {
                        sim = u.Sim2; tsim = "sim2";
                    }
                    var r = Send(u.PhoneId, u.Pin, tsim, data.Phone, content);
                    res.Code = r == true ? HttpStatusCode.OK : HttpStatusCode.BadRequest;

                    if (res.Code != System.Net.HttpStatusCode.OK)
                    {
                        string contentNotify = $"Kiểm tra lại tích hợp sms {u.Name} trên punnel của bạn & kiểm tra lại ứng dụng gửi sms trên điện thoại còn hoạt động không";
                        new Utils.EmailUtils(new Entities.Integration.Gmail.EmailToModel()
                        {
                            Email     = user.Email,
                            FullName  = user.FullName,
                            AvatarUrl = user.Avatar
                        }).SendNotify_AutoReplyError(contentNotify);
                    }
                }
            }catch (Exception ex)
            {
                _log.Error(ex);
            }
            return(res);
        }