Exemple #1
0
        //To Do: Test email functionality
        /// <summary>
        /// Sends access key to join Owner Account via email
        /// This gives permissions to edit another persons inventory
        /// </summary>
        /// <param name="senderFullName"></param>
        /// <param name="secondaryEmail"></param>
        /// <param name="accessKey"></param>
        /// <returns></returns>
        public static bool EmailSecondaryAccessRequest(string senderFullName, string secondaryEmail, string accessKey)
        {
            //email message
            MailMessage mail = new MailMessage();

            mail.To.Add(secondaryEmail.Trim());
            mail.From            = new MailAddress(Creds.EmailCreds(), "Message: Account Requests Action", System.Text.Encoding.UTF8);
            mail.Subject         = "AllStocked Account Permission Request";
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body            = "Hello, You have been invited to become a secondary account on AllStocked. <br>";
            mail.Body           += "Please log in and manage your accounts on your settings page.<br>";
            mail.Body           += "Here is your Access Key: " + accessKey + " <br>";
            mail.Body           += "For the Account Owner: " + senderFullName;

            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml   = true;
            mail.Priority     = MailPriority.High;

            //email Credentials for outlook
            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential(Creds.EmailCreds(), Creds.Psswrd());
            client.Port        = 587;
            client.Host        = "smtp-mail.outlook.com";
            client.EnableSsl   = true;

            try
            {
                client.Send(mail);
                return(true);
            }
            catch (Exception ex)
            {
                //TO DO: Some exception handling I viewed on the Stack, will look into it..
                Exception ex2          = ex;
                string    errorMessage = string.Empty;
                while (ex2 != null)
                {
                    errorMessage += ex2.ToString();
                    ex2           = ex2.InnerException;
                }

                return(false);
            }
            finally
            {
                mail.Dispose();
                client.Dispose();
            }
        }
Exemple #2
0
        /// <summary>
        /// sends recoveryKey to userEmail
        /// </summary>
        /// <param name="userEmail"></param>
        /// <param name="recoveryKey"></param>
        /// <returns></returns>
        public static bool EmailRecoveryKey(string userEmail, string recoveryKey)
        {
            //email message
            MailMessage mail = new MailMessage();

            mail.To.Add(userEmail.Trim());
            mail.From            = new MailAddress(Creds.EmailCreds(), "Password Recovery", System.Text.Encoding.UTF8);
            mail.Subject         = "AllStocked password recovery";
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body            = "Your Recovery Key is =  " + recoveryKey;
            mail.BodyEncoding    = System.Text.Encoding.UTF8;
            mail.IsBodyHtml      = true;
            mail.Priority        = MailPriority.High;

            //email Credential for outlook
            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential(Creds.EmailCreds(), Creds.Psswrd());
            client.Port        = 587;
            client.Host        = "smtp-mail.outlook.com";
            client.EnableSsl   = true;

            try
            {
                client.Send(mail);
                return(true);
            }
            catch (Exception ex)
            {
                //TO DO: Some exception handling I viewed on the Stack, will look into it..
                Exception ex2          = ex;
                string    errorMessage = string.Empty;
                while (ex2 != null)
                {
                    errorMessage += ex2.ToString();
                    ex2           = ex2.InnerException;
                }

                return(false);
            }
            finally
            {
                mail.Dispose();
                client.Dispose();
            }
        }