Beispiel #1
0
        public static void Send(Mail mail)
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(mail.From, "Money Pacific Service");
            msg.To.Add(new MailAddress(mail.To));
            msg.Subject = mail.Subject;
            msg.Body = mail.Body;

            msg.IsBodyHtml = true;
            msg.BodyEncoding = new System.Text.UTF8Encoding();
            msg.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            System.Net.NetworkCredential user = new
                System.Net.NetworkCredential(
                    ConfigurationManager.AppSettings["sender"],
                    ConfigurationManager.AppSettings["senderPass"]
                    );

            smtp.EnableSsl = true;
            smtp.Credentials = user;
            smtp.Port = 587; //or use 465 
            object userState = msg;

            try
            {
                //you can also call client.Send(msg)
                smtp.SendAsync(msg, userState);
            }
            catch (SmtpException)
            {
                //Catch errors...
            }
        }
        public ActionResult SendSMS(PacificCodeSendSMSViewModel obj)
        {
            Customer existCustomer = CustomerBUS.getCustomer(obj.PhoneNumber);
            string sMessage = "";
            if (existCustomer != null)
            {
                PacificCode lastPacifiCode = PacificCodeBUS.GetLastPacificCode(existCustomer.Id);
                // Luôn luôn khi có KH thì đã có PacificCode ?
                // => ko can kiem tra tồn tại?
                DateTime createTime;
                if (lastPacifiCode == null)
                {
                    createTime = DateTime.MinValue;
                }
                else
                {
                    createTime = (DateTime)lastPacifiCode.Date;
                }

                if (createTime.AddHours(24) > DateTime.Now)
                {
                    bool bExist = TransactionBUS.isExist(lastPacifiCode.CodeNumber);
                    if (!bExist)
                    {
                        sMessage = "Da gui lai tin nhan";
                        Mail newMail = new Mail();
                        newMail.Body = "GSM: " + existCustomer.Phone + "<br/>"
                            + "Ban vua mua mot PacificCode: " + lastPacifiCode.CodeNumber
                            + " co gia tri  " + lastPacifiCode.ActualAmount + " VND. "
                            + "va han su dung de ngay {2}";

                        MPMail.SendForEmail(newMail);
                    }
                }
                else
                {
                    sMessage = "Da qua 24 gio tu luc PacificCode duoc tao";
                }
            }
            else
            {
                sMessage = "Khach hang " + obj.PhoneNumber + " khong ton tai.";
            }
            ViewData["message"] = sMessage;
            return View();
        }
        public ActionResult SendMoney(PacificCodeSendMoneyViewModel sendObject)
        {
            try
            {
                // Service

                if (sendObject.PhoneNumber == sendObject.PhoneNumberConfirm)
                {
                    PacificCode newPacificCode = PacificCodeBUS.SendMoney(sendObject.CodeNumber,
                        sendObject.PhoneNumber, sendObject.Amount);

                    if (newPacificCode != null)
                    {
                        // Nếu thành công thì gửi mail thông báo
                        Mail newMail = new Mail();
                        newMail.Subject = "Send to Customer";
                        newMail.Body = "GSM: " + sendObject.PhoneNumber + "<br/>"
                            + "Bạn vừa nhận được PacificCode: " + newPacificCode.CodeNumber + ". "
                            + "Có giá trị " + newPacificCode.ActualAmount + " và "
                            + "han su dung den ngay " + String.Format("{0:dd-MM-yyyy}", newPacificCode.ExpireDate);

                        MPMail.SendForEmail(newMail);
                        ViewData["message"] = "Thuc hien chuyen tien thanh cong!...";
                        return View(sendObject);
                    }
                }

                ViewData["message"] = "Sai thong tin nhap...";
                return View(sendObject);
            }
            catch
            {
                ViewData["message"] = "Co loi xay ra!...";
                return View(sendObject);
            }
        }
Beispiel #4
0
 public static void SendForEmail(Mail mail)
 {
     mail.To = ConfigurationManager.AppSettings["MP_Mail"];
 }