/// <summary>
 ///  Use to send messages via e-mail to specific account.
 /// </summary>
 /// <param name="acc">Account , to which e-mail will be sended.</param>
 /// <param name="text">Sended text</param>
 /// <param name="sub">Subject of letter</param>
 public static void SendMail(Account acc, string text,string sub)
 {
     MailAddress fromAddress = new MailAddress("*****@*****.**", "SolarAnalys");
     var toAddress = new MailAddress(acc.Email);
     string fromPassword = "******";
     //AccountSecurityToken token = new AccountSecurityToken(acc);
     string subject=sub??"", body= text??"";
     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(fromAddress, toAddress)
     {
         Subject = subject,
         Body = body
     })
     {
         message.IsBodyHtml = true;
         smtp.Send(message);
     }
 }
 public AccountSecurityToken(Account acc, string param)
 {
     byte[] hash = Encoding.ASCII.GetBytes(acc.UserName + acc.SecurityStamp + param);
     MD5 md5 = new MD5CryptoServiceProvider();
     byte[] hashex = md5.ComputeHash(hash);
     Token = "";
     foreach (var b in hashex)
     {
         Token += b.ToString("x2");
     }
 }
        /// <summary>
        /// Standart constructor of MessageGenerator for changimg email and password messages
        /// </summary>
        /// <param name="type">Type of message (ChangeEmail,RestorePassword,ChangePassword)</param>
        /// <param name="acc">Account , for which message will be generated</param>
        /// <param name="param"> optional parameters for ChangeEmail and ChangePassword types</param>
        public MessageGenerator(string type,Account acc,string info)
        {
            string domain = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
            string action , param ;

            switch (type)
            {
                case "ChangeEmail":
                    action = new UrlHelper(HttpContext.Current.Request.RequestContext).Action("ConfirmEmail", "User");
                    param = info;

                    Subject = "Зміна Email";
                    Message = "Шановний " + acc.FirstName + " " + acc.LastName + ".<br/> Для зміни вашої пошти , перейдіть по <a href=\"" + $"{domain}{action}{param}" + "\">цій  адресі</a> <br/> Щиро ваша , команда SolarAnalys";

                    break;

                case "RestorePassword"://wrong interpretation
                    action = new UrlHelper(HttpContext.Current.Request.RequestContext).Action("ConfirmPassword", "User");
                    param = info;

                    Subject = "Відновлення паролю";
                    Message = "Шановний " + acc.FirstName + " " + acc.LastName + ".<br/> Для зміни вашого паролю , перейдіть по <a href=\"" + $"{domain}{action}{param}" + "\">цій  адресі</a> <br/> Щиро ваша , команда SolarAnalys";

                    break;

                case "ChangePassword":
                    action = new UrlHelper(HttpContext.Current.Request.RequestContext).Action("ConfirmPassword", "User");
                    param = info;

                    Subject = "Відновлення паролю";
                    Message = "Шановний " + acc.FirstName + " " + acc.LastName + ".<br/> Для підтвердження зміни вашого паролю , перейдіть по <a href=\"" + $"{domain}{action}{param}" + "\">цій  адресі</a> <br/> Щиро ваша , команда SolarAnalys";

                    break;

                default:
                    Subject = "Test";
                    Message = "Test";
                    break;
            }
        }