示例#1
0
        public async Task <IActionResult> Subscribe(string email)
        {
            try
            {
                MailAddress from    = new MailAddress("*****@*****.**", "*****@*****.**");
                MailAddress to      = new MailAddress(email);
                MailMessage message = new MailMessage(from, to);
                message.Subject    = "EBookSharing - Weekly news";
                message.Body       = "<h2>Спасибо большое за подписку!</h2>";
                message.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                smtp.Credentials = new NetworkCredential("*****@*****.**", PasswordHelper.EmailPassword());
                smtp.EnableSsl   = true;
                await smtp.SendMailAsync(message);

                return(Redirect("Index?subscribed=yes"));
            }
            catch (Exception e)
            {
                return(Redirect("Index?subscribed=no"));
            }
        }