public async void SendFirstEmails(LoadBuyRequest request)
        {
            //  Valores del primer email al cliente
            var format          = _orderDataAccess.GetEmailFormat(1);
            var sendEmailClient = new SendEmailEntity()
            {
                Email     = request.NewClient.Email,
                NameEmail = request.NewClient.Name + request.NewClient.Surname,
                Subject   = "Orden de compra n° " + request.IdOrder,
                Body      = format
            };

            sendEmailClient.Body = sendEmailClient.Body.Replace("{OrderNumber}", request.IdOrder.ToString());
            sendEmailClient.Body = sendEmailClient.Body.Replace("{TotalAmount}", "$" + request.TotalAmount.ToString());
            await _mailer.SendEmailAsync(sendEmailClient);

            //  Valores del primer email a farma
            var sendEmailSale = new SendEmailEntity()
            {
                Email     = "*****@*****.**",
                NameEmail = "Venta",
                Subject   = "Orden de compra n° " + request.IdOrder,
                Body      = "Nueva Venta! " + "</br>" + "{Obj}"
            };
            string requestString = JsonSerializer.Serialize(request);

            sendEmailSale.Body = sendEmailSale.Body.Replace("{OrderNumber}", request.IdOrder.ToString());
            sendEmailSale.Body = sendEmailSale.Body.Replace("{Obj}", requestString);
            await _mailer.SendEmailAsync(sendEmailSale);
        }
Example #2
0
 public async void SendNextEmail(LoadBuyRequest request)
 {
     var sendEmailEntity = new SendEmailEntity()
     {
         Email     = request.NewClient.Email,
         NameEmail = request.NewClient.Name + request.NewClient.Surname,
         Subject   = "Orden de compra n°" + request.IdOrder,
         Body      = ""
     };
     await _mailer.SendEmailAsync(sendEmailEntity);
 }
Example #3
0
        public async void SendNextEmail(GetOrderDetailResponse request)
        {
            var format          = _orderDataAccess.GetEmailFormat(request.IdStateOrder);
            var sendEmailEntity = new SendEmailEntity()
            {
                Email     = request.ClientEmail,
                NameEmail = request.ClientName + request.ClientSurname,
                Subject   = "Orden de compra n° " + request.IdOrder,
                Body      = format
            };

            sendEmailEntity.Body = sendEmailEntity.Body.Replace("{OrderNumber}", request.IdOrder.ToString());
            await _mailer.SendEmailAsync(sendEmailEntity);
        }
Example #4
0
        public async Task <IActionResult> ExportDate()
        {
            MASFARMACIADEVContext context = new MASFARMACIADEVContext();
            var query           = context.EmailsFormatEntity.Find(1);
            var sendEmailEntity = new SendEmailEntity()
            {
                Email     = "*****@*****.**",
                NameEmail = "Remitente",
                Subject   = "Orden de compra n°" + 0001,
                Body      = query.Format
            };
            await _mailer.SendEmailAsync(sendEmailEntity);

            return(NoContent());
        }
        public void ExportDate(LoadBuyRequest request)
        {
            MASFARMACIADEVContext context = new MASFARMACIADEVContext();
            var sendEmailSale             = new SendEmailEntity()
            {
                Email     = "*****@*****.**",
                NameEmail = "Venta",
                Subject   = "Orden de compra n° " + request.IdOrder,
                Body      = "Nueva Venta! /br {Obj}"
            };

            sendEmailSale.Body = sendEmailSale.Body.Replace("{OrderNumber}", request.IdOrder.ToString());
            sendEmailSale.Body = sendEmailSale.Body.Replace("{Obj}", request.ToString());
            _mailer.SendEmailAsync(sendEmailSale);
        }
        public async Task <SendEmailDomain> SendAndLogEmailAsync(SendEmailDomain email)
        {
            string emailAddress     = email.Address;
            string emailDisplayName = email.DisplayName;

            // Send email
            var emailToSend = new Email(email.Subject, email.Body, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName));

            emailToSend.To.Add(new EmailAddress(email.Emails.First(), emailDisplayName)); //Email must always have a valid recipient
            emailToSend.Headers.AddRange(email.Emails);                                   // Must always add to headers for utilizing send-grid api

            await _mailerRepository.SendMail(emailToSend);

            email.Id      = ((int)email.Template) + GetUtcTimestamp();
            email.Created = DateTime.UtcNow;

            // Log sent email
            SendEmailEntity entity = _mapper.Map <SendEmailDomain, SendEmailEntity>(email);
            await _sendEmailRepository.AddAsync(entity);

            return(email);
        }
Example #7
0
        public async Task SendEmailAsync(SendEmailEntity sendEmailEntity)
        {
            try
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress(_smtpSettings.SenderName, _smtpSettings.SenderEmail));
                message.To.Add(new MailboxAddress(sendEmailEntity.NameEmail, sendEmailEntity.Email));
                message.Subject = sendEmailEntity.Subject;
                message.Body    = new TextPart("html")
                {
                    Text = sendEmailEntity.Body
                };

                using (var client = new SmtpClient())
                {
                    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                    if (_env.IsDevelopment())
                    {
                        await client.ConnectAsync(_smtpSettings.Server, _smtpSettings.Port, MailKit.Security.SecureSocketOptions.StartTls);
                    }
                    else
                    {
                        await client.ConnectAsync(_smtpSettings.Server);
                    }
                    await client.AuthenticateAsync(_smtpSettings.Username, _smtpSettings.Password);

                    await client.SendAsync(message);

                    await client.DisconnectAsync(true);
                }
            }
            catch (Exception msg)
            {
                throw new InvalidOperationException(msg.Message);
            }
        }
Example #8
0
        public ExhibitionModule()
            : base("/Exhibition")
        {
            #region  设置展场根据时间展示
            Get["/ActivityTime"] = _ =>
            {
                BCtrl_Exhibition exhibition = new BCtrl_Exhibition();
                bool             isPush     = exhibition.IsPublished();
                return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 1, Msg = "数据传输完成!!", Value = isPush }));

                //return JsonObj<JsonMessageBase<bool>>.ToJson(new JsonMessageBase<bool>() { Status = 1, Msg = "数据传输完成!!", Value = true });
            };
            #endregion

            #region  获取是否是版本审核
            Get["/CheckState"] = _ =>
            {
                try
                {
                    BCtrl_Common commonobj = new BCtrl_Common();
                    dynamic      data      = FecthQueryData();
                    string       verCode   = data.VerCode; //string verCode = "1";
                    bool         isCheck   = commonobj.IsVersionCheck(verCode);
                    return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 1, Msg = "Data transfer Complete!!", Value = isCheck }));
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(ex);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "Failed to connect to the server,Try again later."
                    }));
                }
            };
            #endregion

            #region 发送邮件
            Get["/SendEmail"] = _ =>
            {
                dynamic data = FecthQueryData();
                ExhibitionEmailEntity entity = new ExhibitionEmailEntity();
                string eID   = data.Eid;      //展场ID
                string cID   = data.UserID;   //用户ID
                string cName = data.NickName; //用户名
                string email = data.Email;    //email

                int exhibitionID = 0;
                int customerID   = 0;
                int.TryParse(eID, out exhibitionID);
                int.TryParse(cID, out customerID);
                entity.ExhibitionID  = exhibitionID;
                entity.CustomerID    = customerID.ToString();
                entity.CustomerName  = cName;
                entity.CustomerEmail = email;
                entity.CreateTime    = DateTime.Now;
                entity.SendTypeID    = 0;
                //展场邮件时间设定
                DateTime?sendTime = DateTime.Parse("2016-01-07 08:20:00");

                if (entity.CustomerName == null || string.IsNullOrEmpty(entity.CustomerName))
                {
                    entity.CustomerName = "开卷日历大客户";
                }

                if (entity.CreateTime < sendTime) // 测试 求反
                {
                    entity.SendTime = sendTime;
                    BCtrl_ExhibitionEmail.Instance.ExhibitionEmail_Insert(entity);
                }
                else
                {
                    entity.SendTime = entity.CreateTime;
                    SendEmailEntity sendEntity = new SendEmailEntity();
                    BCtrl_UserMail  bllMail    = new BCtrl_UserMail();
                    List <CompanyEmailAccountEntity> mailList = bllMail.QueryCoEmailAccountList();
                    Random rd = new Random();
                    if (mailList == null || mailList.Count == 0)
                    {
                        return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 0, Msg = "邮箱服务器地址库为空!!", Value = false }));
                    }
                    //随机找出一个服务器地址
                    int num = rd.Next(0, mailList.Count - 1);
                    #region 发送邮件固定参数
                    CompanyEmailAccountEntity cea = mailList[num];
                    sendEntity.FromEmail    = cea.EmailName;
                    sendEntity.FromSendName = "开卷网络";
                    sendEntity.FromPassword = cea.EmailPassword;
                    sendEntity.ToSendName   = entity.CustomerName;
                    sendEntity.ToEmail      = entity.CustomerEmail;
                    sendEntity.Subject      = "2016年北京图书订货会电子书目——由北京开卷收集整理";
                    sendEntity.Body         = "基于2016年图书订货会,这是开卷搜集并整理订货会参展商的电子书目。";
                    sendEntity.Body        += "<span style='font-family: Arial; line-height: 23.8px; color: rgb(255, 255, 255); background-color: rgb(255, 0, 0);'>【此文件大小超过3G,请务必使用电脑进行下载】</span> <br />";
                    sendEntity.Body        += "下载链接: http://pan.baidu.com/s/1bpjF5c ";
                    sendEntity.Body        += "密码: ijex   <br />";
                    sendEntity.Body        += "开卷日历APP——网络书业人和事。<br />";
                    sendEntity.Body        += "<img src='http://7xkwie.com2.z0.glb.qiniucdn.com/20151201/e3834448-e386-45b8-93cc-01a92744e5e8.jpg' alt='扫一扫' ></img>";
                    #endregion
                    bool state = SendEmail.Send(sendEntity);
                    if (state)
                    {
                        //单条发送时,发送后改变发送状态
                        entity.SendTypeID = 1;
                        BCtrl_ExhibitionEmail.Instance.ExhibitionEmail_Insert(entity);
                    }
                }
                return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 1, Msg = "数据传输完成!!", Value = true }));
            };
            #endregion
        }
Example #9
0
        /// <summary>
        /// EmailTiming 邮件定时提醒  2016-01-04 08:20:00 发送完以后 销毁
        /// </summary>
        public static void EmailTiming()
        {
            DateTime?sendTime = DateTime.Parse("2016-01-07 08:20:00");

            new System.Threading.Thread(() =>
            {
                while (true)
                {
                    if (DateTime.Now < sendTime)
                    {
                        //5分钟
                        System.Threading.Thread.Sleep(60 * 1000 * 5);
                    }
                    else
                    {
                        BCtrl_UserMail bllMail = new BCtrl_UserMail();
                        List <CompanyEmailAccountEntity> mailList = bllMail.QueryCoEmailAccountList();
                        if (mailList == null || mailList.Count == 0)
                        {
                            break;
                        }
                        OperationResult <IList <ExhibitionEmailEntity> > result =
                            BCtrl_ExhibitionEmail.Instance.ExhibitionEmail_GetWhere(" AND SendTypeID =0 ");
                        if (result.ResultType == OperationResultType.Success)
                        {
                            var entitys = result.AppendData;
                            entitys     = entitys.GroupBy(p => new { p.CustomerEmail }).Select(g => g.First()).ToList();

                            for (int i = 0; i < entitys.Count; i++)
                            {
                                //随机挑出一个服务器地址
                                Random rd = new Random();
                                int num   = rd.Next(0, mailList.Count - 1);
                                SendEmailEntity sendEntity = new SendEmailEntity();

                                #region 发送邮件固定参数
                                CompanyEmailAccountEntity cea = mailList[num];
                                sendEntity.FromEmail          = cea.EmailName;
                                sendEntity.FromSendName       = "开卷网络";
                                sendEntity.FromPassword       = cea.EmailPassword;

                                sendEntity.ToSendName = entitys[i].CustomerName;
                                sendEntity.ToEmail    = entitys[i].CustomerEmail;
                                sendEntity.Subject    = "2016年北京图书订货会电子书目——由北京开卷收集整理";
                                sendEntity.Body       = "基于2016年图书订货会,这是开卷搜集并整理订货会参展商的电子书目。<br />";
                                sendEntity.Body      += "下载链接: http://pan.baidu.com/s/1bpjF5c ";
                                sendEntity.Body      += "密码: ijex   <br />";
                                sendEntity.Body      += "开卷日历APP——网络书业人和事。<br />";
                                sendEntity.Body      += "<img src='http://7xkwie.com2.z0.glb.qiniucdn.com/20151201/e3834448-e386-45b8-93cc-01a92744e5e8.jpg' alt='扫一扫' ></img>";
                                #endregion

                                bool state = SendEmail.Send(sendEntity);
                                if (state)
                                {
                                    //单条发送时,发送后改变发送状态
                                    entitys[i].SendTypeID = 1;
                                    BCtrl_ExhibitionEmail.Instance.ExhibitionEmail_UpdateSendTypeID(entitys[i].CustomerEmail, entitys[i].SendTypeID);
                                }
                            }
                        }

                        break;
                    }
                }
            }).Start();
        }
Example #10
0
        public SignBookModule() : base("SignBook")
        {
            #region 判定是否报到客户  2015/11/12
            Get["IsAllow"] = _ =>
            {
                dynamic data        = FecthQueryData();
                string  customerKey = data.CustomerKey;
                bool    flag        = BCtrl_SignBook.Instance.IsAllowCustomerKey(customerKey);
                if (!flag)
                {
                    marsLog.InfoFormat("IsAllow 未找到的用户Key:" + customerKey);
                }
                return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase <string>() { Status = 1, Msg = "客户已签到", Value = flag.ToString() }));
            };
            #endregion

            #region 返回客户的二维码地址 2015/11/12
            Get["GetQRCode"] = _ =>
            {
                dynamic data                  = FecthQueryData();
                string  customerKey           = data.CustomerKey;
                IList <SignBookEntity> entity = BCtrl_SignBook.Instance.SignBook_Get(customerKey);
                if (entity == null || entity.Count == 0)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "数据接收成功,但没有实际改变"
                    }));
                }
                string url = System.Configuration.ConfigurationManager.AppSettings["WebRoot"].ToString() + "/SignBook/Details.aspx?sid=" + entity[0].SignID;
                //string url = "http://www.kjrili.com/SignBook/Details.aspx?sid=" + entity[0].SignID;
                return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase <string>() { Status = 1, Msg = "数据接收成功", Value = url }));
            };
            #endregion


            #region 发送邮件
            Get["/SendEmail"] = _ =>
            {
                dynamic data = FecthQueryData();
                ExhibitionEmailEntity entity = new ExhibitionEmailEntity();
                string eID   = data.Eid;      //展场ID
                string cID   = data.UserID;   //用户ID
                string cName = data.NickName; //用户名
                string email = data.Email;    //email

                int exhibitionID = 0;
                int customerID   = 0;
                int.TryParse(eID, out exhibitionID);
                int.TryParse(cID, out customerID);
                entity.ExhibitionID  = exhibitionID;
                entity.CustomerID    = customerID.ToString();
                entity.CustomerName  = cName;
                entity.CustomerEmail = email;
                entity.CreateTime    = DateTime.Now;
                entity.SendTypeID    = 0;
                //展场邮件时间设定
                DateTime?sendTime = DateTime.Parse("2016-01-07 08:20:00");

                if (entity.CustomerName == null || string.IsNullOrEmpty(entity.CustomerName))
                {
                    entity.CustomerName = "开卷日历大客户";
                }

                if (entity.CreateTime < sendTime) // 测试 求反
                {
                    entity.SendTime = sendTime;
                    BCtrl_ExhibitionEmail.Instance.ExhibitionEmail_Insert(entity);
                }
                else
                {
                    entity.SendTime = entity.CreateTime;
                    SendEmailEntity sendEntity = new SendEmailEntity();
                    BCtrl_UserMail  bllMail    = new BCtrl_UserMail();
                    List <CompanyEmailAccountEntity> mailList = bllMail.QueryCoEmailAccountList();
                    Random rd = new Random();
                    if (mailList == null || mailList.Count == 0)
                    {
                        return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 0, Msg = "邮箱服务器地址库为空!!", Value = false }));
                    }
                    //随机找出一个服务器地址
                    int num = rd.Next(0, mailList.Count - 1);
                    #region 发送邮件固定参数
                    CompanyEmailAccountEntity cea = mailList[num];
                    sendEntity.FromEmail    = cea.EmailName;
                    sendEntity.FromSendName = "开卷网络";
                    sendEntity.FromPassword = cea.EmailPassword;
                    sendEntity.ToSendName   = entity.CustomerName;
                    sendEntity.ToEmail      = entity.CustomerEmail;
                    sendEntity.Subject      = "2016年北京图书订货会电子书目——由北京开卷收集整理";
                    sendEntity.Body         = "基于2016年图书订货会,这是开卷搜集并整理订货会参展商的电子书目。";
                    sendEntity.Body        += "<span style='font-family: Arial; line-height: 23.8px; color: rgb(255, 255, 255); background-color: rgb(255, 0, 0);'>【此文件大小超过3G,请务必使用电脑进行下载】</span> <br />";
                    sendEntity.Body        += "下载链接: http://pan.baidu.com/s/1bpjF5c ";
                    sendEntity.Body        += "密码: ijex   <br />";
                    sendEntity.Body        += "开卷日历APP——网络书业人和事。<br />";
                    sendEntity.Body        += "<img src='http://7xkwie.com2.z0.glb.qiniucdn.com/20151201/e3834448-e386-45b8-93cc-01a92744e5e8.jpg' alt='扫一扫' ></img>";
                    #endregion
                    bool state = SendEmail.Send(sendEntity);
                    if (state)
                    {
                        //单条发送时,发送后改变发送状态
                        entity.SendTypeID = 1;
                        BCtrl_ExhibitionEmail.Instance.ExhibitionEmail_Insert(entity);
                    }
                }
                return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 1, Msg = "数据传输完成!!", Value = true }));
            };
            #endregion
        }