Exemple #1
0
        public async Task <int> SendEmail(V_CSCOAGM vCSCOAGM)
        {
            if (string.IsNullOrEmpty(vCSCOAGM.Email))
            {
                return(0);
            }


            string html = RenderViewToString(ControllerContext, "~/views/VCSCOAGM/Reminder.cshtml", vCSCOAGM, true);

            //string filename = @"c:\temp\email.html";
            //var sw = new System.IO.StreamWriter(filename, true);
            //sw.WriteLine(html);
            //sw.Close();

            EmailFormModel model = new WebApplication1.EmailFormModel();

            model.Message   = html;
            model.FromEmail = "*****@*****.**";
            model.FromName  = "ASI Secretary";

            var body    = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();

            message.To.Add(new MailAddress(vCSCOAGM.Email)); //replace with valid value
            message.Subject    = "Financial Statement Reminder";
            message.Body       = string.Format(body, model.FromName, model.FromEmail, model.Message);
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {
                await smtp.SendMailAsync(message);
            }
            return(1);
        }
Exemple #2
0
        public async Task <ActionResult> Email(string id)
        {
            string sid   = MyHtmlHelpers.ConvertByteStrToId(id);
            CSPRF  cSPRF = getProforma(sid);


            string html = RenderViewToString(ControllerContext, "~/views/CSPRFs/Proforma.cshtml", cSPRF, true);

            EmailFormModel model = new WebApplication1.EmailFormModel();

            model.Message   = html;
            model.FromEmail = "*****@*****.**";
            model.FromName  = "ASI Secretary";

            var body    = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();

            message.To.Add(new MailAddress(cSPRF.CSCOMSTR.WEB)); //replace with valid value
            message.Subject    = "Proforma Billing " + cSPRF.PRFNO;
            message.Body       = string.Format(body, model.FromName, model.FromEmail, model.Message);
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {
                await smtp.SendMailAsync(message);

                return(RedirectToAction("Sent", "Home"));
            }


            //var credential = new NetworkCredential
            //{
            //    UserName = "******",  // replace with valid value
            //    Password = "******"  // replace with valid value
            //};
            //smtp.Credentials = credential;
            //smtp.Host = "smtp-mail.outlook.com";
            //smtp.Port = 587;
            //smtp.EnableSsl = true;
            //await smtp.SendMailAsync(message);
            //return RedirectToAction("Sent");



            return(View("Proforma", cSPRF));
        }