public static bool SendEmail(SMTPemail smtp, string Email, string Password, string UserName)
        {
            string fromStr  = smtp.EmailUsernames;
            string fromName = smtp.FromName;

            System.Net.Mail.MailAddress fromAddr = new System.Net.Mail.MailAddress(fromStr, fromName, System.Text.Encoding.UTF8);
            System.Net.Mail.MailAddress toAddr   = new System.Net.Mail.MailAddress(Email, "user", System.Text.Encoding.UTF8);
            System.Net.Mail.MailMessage message  = new System.Net.Mail.MailMessage(fromAddr, toAddr);

            string body = "<html><body><p>Hi ,<br/><br/>";

            body += "Your Password is:<strong>" + Password + "</strong><br/>";
            body += "Your UserName is:<strong>" + UserName + "</strong><br/>";
            body += "Please do not share these details with anybody.<br/>";
            body += "Regards<br/>";
            body += "Password Manager<br/>";
            body += "<br/></p></body></html>";



            System.Net.Mail.AlternateView htmlView  = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, "text/html");
            System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(body, @"<(.|\n)*?>", string.Empty), null, "text/plain");

            System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient(smtp.SMTPservers, int.Parse(smtp.EmailPorts));

            message.IsBodyHtml = true;

            message.Subject         = "Password " + fromName;
            message.SubjectEncoding = System.Text.Encoding.UTF8;

            message.Headers.Add("Return-Path", fromName + "<" + fromStr + ">");
            message.Headers.Add("Reply-To", fromName + "<" + fromStr + ">");
            message.Headers.Add("From", fromName + "<" + fromStr + ">\r\n");
            message.Headers.Add("Organization", "Get Balance");
            message.Headers.Add("MIME-Version", "1.0\r\n");
            message.Headers.Add("Content-type", "text/html; charset=ISO-8859-1\r\n");
            DateTime now = DateTime.Now;

            message.Headers.Add("Message-Id", String.Concat("<", now.ToString("yyMMdd"), ".", now.ToString("HHmmss"), "@Tetramind.com"));
            message.Priority = System.Net.Mail.MailPriority.High;
            message.ReplyTo  = fromAddr;
            message.From     = fromAddr;

            message.Sender = fromAddr;


            mailclient.UseDefaultCredentials = false;

            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.Body         = body;


            message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnFailure;

            mailclient.EnableSsl   = true;
            mailclient.Credentials = new System.Net.NetworkCredential(fromStr, smtp.EmailPasswords);
            mailclient.Send(message);

            return(true);
        }
Ejemplo n.º 2
0
        public ActionResult Add(SMTPemail smtpe)
        {
            if (SessionContext.CurrentUser != null)
            {
                //Save SMTP
                SMTP smtp = new SMTP();
                smtp.ServerName = smtpe.ServerName;
                smtp.Port       = smtpe.Port;
                smtp.SSL        = smtpe.SSL;
                var Smtp = db.SMTP.Add(smtp);
                db.SaveChanges();

                //Save POP
                PoPP pop = new PoPP();
                pop.ServerName = smtpe.PServerName;
                pop.Port       = smtpe.PPort;
                pop.SSL        = smtpe.PSSL;
                var Pop = db.PoPP.Add(pop);
                db.SaveChanges();

                //Save Email
                CnfiEmail cnf = new CnfiEmail();
                cnf.Email    = smtpe.Email;
                cnf.password = smtpe.Password;
                cnf.Sid      = Smtp.Sid;
                cnf.Pid      = Pop.Pid;
                cnf.Uid      = SessionContext.CurrentUser.Uid;
                var Email = db.CnfiEmail.Add(cnf);
                db.SaveChanges();
                return(RedirectToAction("Index", "Dashboards"));
            }
            return(RedirectToAction("Login", "Account"));
        }
Ejemplo n.º 3
0
        public ActionResult ForgotPassword(UserForgotPassUI model)
        {
            string Error = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(model.Email))
                    {
                        throw new ApplicationException("Invalid Email");
                    }

                    var user = db.tblUserLoginInfoes.Where(m => m.Email_id == model.Email).FirstOrDefault();

                    if (user == null)
                    {
                        throw new ApplicationException("User not found for this email. Please enter valid email.");
                    }
                    SMTPemail smtp = new SMTPemail
                    {
                        EmailUsernames = EmailUsername,
                        EmailPorts     = EmailPort,
                        EmailPasswords = EmailPassword,
                        SMTPservers    = SMTPserver,
                        FromName       = "totalent"
                    };

                    SendEmail(smtp, user.Email_id, user.Password, user.UserName);

                    ViewBag.Success = "We have sent you password please check your mail.";
                }
                else
                {
                    Error = "Please enter required details";
                }
            }
            catch (ApplicationException ex)
            {
                Error = ex.Message.ToString();
            }
            catch (Exception ex)
            {
                Error = "Server error. please try again!";
            }

            ViewBag.Error = Error;
            return(View());
        }