Exemplo n.º 1
0
        public async Task <ActionResult> Index(string subscribe)
        {
            bool status = true;

            db.subscribe(subscribe);

            var body    = "<h2>Welcome to the Big Bang Store</h2><p>Dear Customer,</p><br/><p>Thanks for registering Big Bang Store.</p>";
            var message = new MailMessage();

            message.To.Add(new MailAddress(subscribe));
            /*message.To.Add(new MailAddress("*****@*****.**"));*/ // replace with valid value
            message.From = new MailAddress("*****@*****.**");    // replace with valid value

            message.Subject    = "Your email subject";
            message.Body       = string.Format(body, "from name", "from email", "message");
            message.IsBodyHtml = true;

            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    //UserName = "******",  // replace with valid value
                    //Password = "******"  // replace with valid value2
                    UserName = "******", // replace with valid value
                    Password = "******"                         // replace with valid value2
                };
                smtp.Credentials = credential;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.EnableSsl   = true;
                await smtp.SendMailAsync(message);

                return(new JsonResult {
                    Data = new { status = status }
                });
            }
        }