Ejemplo n.º 1
0
        public async Task <JsonResult> SendEmail(string template, string sendmail, string lastdate, string email, string name, string c, string m, string box, string b, string i, string n, string all)
        {
            try
            {
                string emailTemplate;
                string url;
                switch (template)
                {
                case "A產品":
                    emailTemplate = "AProduct";
                    url           = "http://www.trible.io";
                    break;

                default:
                    emailTemplate = "BProduct";
                    url           = "http://www.trible.io";
                    break;
                }

                var message = await EMailTemplate(emailTemplate);

                message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name));
                message = message.Replace("@ViewBag.C", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(c));
                message = message.Replace("@ViewBag.M", String.Format(new CultureInfo("en-US"), "{0:N2}", m));
                message = message.Replace("@ViewBag.Box", String.Format(new CultureInfo("en-US"), "{0:N2}", box));
                message = message.Replace("@ViewBag.B", String.Format(new CultureInfo("en-US"), "{0:N2}", b));
                message = message.Replace("@ViewBag.I", String.Format(new CultureInfo("en-US"), "{0:N2}", i));
                message = message.Replace("@ViewBag.N", String.Format(new CultureInfo("en-US"), "{0:N2}", n));
                message = message.Replace("@ViewBag.All", String.Format(new CultureInfo("en-US"), "{0:N2}", all));
                message = message.Replace("@ViewBag.Link", "<a href=\"" + url + "\" style='color:red'>出貨明細</a>");
                message = message.Replace("@ViewBag.LastDate", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(lastdate));
                if (email.Contains(','))
                {
                    List <string> emails = email.Split(',').ToList();
                    foreach (string e in emails)
                    {
                        await EmailServices.SendMailAsync(sendmail, e, "【" + template + "】" + m + "月份紅利計算、發票開立作業---" + c, message);
                    }
                }
                else
                {
                    await EmailServices.SendMailAsync(sendmail, email, "【" + template + "】" + m + "月份紅利計算、發票開立作業---" + c, message);
                }
            }
            catch (Exception)
            {
                return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
        }