Пример #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);
            }
        }
Пример #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);
        }