예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            MsgSetup msgSetup = db.MsgSetups.Find(id);

            db.MsgSetups.Remove(msgSetup);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public ActionResult MsgSettings([Bind(Include = "Id,Email,Password,Port,Host,Backlog")] MsgSetup msgSetup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(msgSetup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(msgSetup));
 }
예제 #3
0
        public ActionResult Create([Bind(Include = "Id,Email,Password,Port,Host,Backlog")] MsgSetup msgSetup)
        {
            if (ModelState.IsValid)
            {
                db.MsgSetups.Add(msgSetup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(msgSetup));
        }
예제 #4
0
        // GET: MsgSetups/Edit/5
        public ActionResult MsgSettings(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MsgSetup msgSetup = db.MsgSetups.Find(id);

            if (msgSetup == null)
            {
                return(HttpNotFound());
            }
            return(View(msgSetup));
        }
예제 #5
0
        void sendMail(IdentityMessage message)
        {
            MsgSetup             setup = new MsgSetup();
            ApplicationDbContext db    = new ApplicationDbContext();

            setup = db.MsgSetups.Where(x => x.Id == 1).FirstOrDefault();
            string line;

            //Pass the file path and file name to the StreamReader constructor

            using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Content/MailTemplates/Confirmation.txt"))
            {
                line = sr.ReadToEnd();
            }

            //Read the first line of text
            //line = sr.ReadLine();

            //var t = line.Split(';').ToList();

            //for (int i = 0; i < t.Count; i++)
            //{
            //    if (i == 0)
            //    {
            //        setup.Email = t[i].ToString();
            //    }
            //    else if (i == 1)
            //    {
            //        setup.Password = t[i].ToString();
            //    }
            //    else if (i == 2)
            //    {
            //        setup.Port = t[i].ToString();
            //    }
            //    else if (i == 3)
            //    {
            //        setup.Host = t[i].ToString();
            //    }
            //}
            //sr.Close();


            #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/>";
            string html = line.Replace("{0}", message.Body);
            //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(setup.Email);
            msg.To.Add(new MailAddress(message.Destination));
            msg.Subject = message.Subject;
            msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
            msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

            SmtpClient smtpClient = new SmtpClient();
            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(setup.Email, setup.Password);
            smtpClient.Host        = setup.Host; //Or Your SMTP Server Address
            smtpClient.Credentials = new System.Net.NetworkCredential(setup.Email, setup.Password);
            smtpClient.Port        = Convert.ToInt32(setup.Port);
            smtpClient.EnableSsl   = true;
            smtpClient.Send(msg);

            //System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Email"].ToString(), ConfigurationManager.AppSettings["Password"].ToString());
            //smtpClient.Host = "mail.staytuneonline.tv"; //Or Your SMTP Server Address
            //smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Email"].ToString(), ConfigurationManager.AppSettings["Password"].ToString());
            //smtpClient.Port = 8889;
            ////smtpClient.EnableSsl = true;
            //smtpClient.Send(msg);


            //===================================================================================================================================
            ////create the mail message
            //MailMessage mail = new MailMessage();

            ////set the addresses
            //mail.From = new MailAddress("*****@*****.**"); //IMPORTANT: This must be same as your smtp authentication address.
            //mail.To.Add("*****@*****.**");

            ////set the content
            //mail.Subject = "This is an email";
            //mail.Body = "This is from system.net.mail using C sharp with smtp authentication.";
            ////send the message
            //SmtpClient smtp = new SmtpClient("mail.staytuneonline.tv");

            ////IMPORANT:  Your smtp login email MUST be same as your FROM address.
            //NetworkCredential Credentials = new NetworkCredential(ConfigurationManager.AppSettings["Email"].ToString(), ConfigurationManager.AppSettings["Password"].ToString());
            //smtp.Credentials = Credentials;
            //smtp.Send(mail);
            //lblMessage.Text = "Mail Sent";
        }