Beispiel #1
0
        public static void SendMail(string to, string subject, string body)
        {
            EmailSettings settings = new EmailSettings();

            string sendAccount = settings.Account;
            string sendPass = settings.Password;

            //#region formatter
            //string text = string.Format("Please click on this link to {0}: {1}", message.Subject, message.Body);
            //string html = "Please confirm your account by clicking this link: <a href=\"" + message.Body + "\">link</a><br/>";

            //html += HttpUtility.HtmlEncode(@"Or click on the copy the following link on the browser:" + message.Body);
            //#endregion

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(sendAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = body;
            //msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
            //msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

            SmtpClient smtpClient = new SmtpClient(settings.SmtpUrl, Convert.ToInt32(settings.SmtpPort));
            smtpClient.EnableSsl = true;
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtpClient.UseDefaultCredentials = false;
            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(sendAccount, sendPass);
            smtpClient.Credentials = credentials;

            smtpClient.Send(msg);
        }
Beispiel #2
0
        public ActionResult EmailSettings()
        {
            EmailSettings settings = new EmailSettings();
            EmailSettingsVM vm = new EmailSettingsVM
            {
                EmailAddress = settings.Account,
                Password = settings.Password,
                SmtpUrl = settings.SmtpUrl,
                SmtpPort = Convert.ToInt32(settings.SmtpPort)
            };

            return View(vm);
        }
Beispiel #3
0
        public ActionResult EmailSettings(EmailSettingsVM viewModel)
        {
            if (ModelState.IsValid)
            {
                EmailSettings settings = new EmailSettings();

                settings.Account = viewModel.EmailAddress;
                settings.Password = viewModel.Password;
                settings.SmtpUrl = viewModel.SmtpUrl;
                settings.SmtpPort = viewModel.SmtpPort.ToString();

                return RedirectToAction("Index", "FillListValues");
            }

            return View(viewModel);
        }