예제 #1
0
        public IHttpActionResult GetPassword([FromBody] EmailDto email)
        {
            string password = UserBl.GetPasswordByemail(email.emailAddress);

            if (password != null)
            {
                try
                {
                    var    fromAddress  = new MailAddress("*****@*****.**", "Dream Cream Team");
                    var    toAddress    = new MailAddress(email.emailAddress, "To User");
                    string fromPassword = "******";
                    string subject      = "שחזור סיסמה";
                    string body         = "<p>סיסמתך היא: " + password + "</p>";

                    var smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                    };
                    using (var message = new MailMessage("*****@*****.**", email.emailAddress, subject, body))
                    {
                        message.IsBodyHtml = true;
                        smtp.Send(message);
                    }
                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(BadRequest("ישנה תקלה, נסה שוב בעוד כמה דקות"));
                }
            }
            return(BadRequest("אימייל אינו קיים במערכת"));
        }