Esempio n. 1
0
        public void TestServerSettings()
        {
            string[] recipients = {"to"};
            EmailSender sender = new EmailSender(recipients, "from", "subject", "content", "attach");

            sender.SmtpServerHost = "testhost";
            sender.SmtpServerPort = 100;
            Assert.AreEqual("testhost", sender.SmtpServerHost);
            Assert.AreEqual(100, sender.SmtpServerPort);
        }
Esempio n. 2
0
 public void TestAuthenticatedNoHost()
 {
     //---------------Set up test pack-------------------
     string[] recipients = { "to" };
     EmailSender sender = new EmailSender(recipients, "from", "subject", "content", "attach");
     //---------------Execute Test ----------------------
     try
     {
         sender.SendAuthenticated("username", "password");
         Assert.Fail("Expected to throw an Exception");
     }
         //---------------Test Result -----------------------
     catch (Exception ex)
     {
         StringAssert.Contains("Please specify the SMTP Host Name before attempting to send", ex.Message);
     }
 }
Esempio n. 3
0
        public void TestInvalidEmail()
        {
            //---------------Set up test pack-------------------
            string[] recipients = { "to" };
            EmailSender sender = new EmailSender(recipients, "from", "subject", "content", "attach");

            //---------------Execute Test ----------------------
            try
            {
                sender.Send();
                Assert.Fail("Expected to throw an Exception");
            }
                //---------------Test Result -----------------------
            catch (Exception)
            {
            }
        }
            private void SendErrorMessage(IDictionary dictionary, string emailContent)
            {
                string smtpServer = (string)dictionary["smtp_server"];
                string emailTo = (string)dictionary["email_to"];
                string[] emailAddresses = emailTo.Split(new char[]{';'});

                string emailFrom = (string)dictionary["email_from"];

                //string emailContent = ExceptionUtilities.GetExceptionString(_exception, 0, true);

                EmailSender emailSender = new EmailSender(emailAddresses, emailFrom, _exception.Source, emailContent, "");
                ////Todo : check Send Authenticated for security purposes?
                
                emailSender.SmtpServerHost = smtpServer;
                string port = (string)dictionary["smtp_port"];
                if (!String.IsNullOrEmpty(port))
                {
                    emailSender.SmtpServerPort = Convert.ToInt32(port);
                }
                bool enableSSL = Convert.ToBoolean(dictionary["smtp_enable_ssl"]); 
                emailSender.EnableSSL = enableSSL;
                emailSender.Send();
            }
Esempio n. 5
0
 public void TestAuthenticatedNoPort()
 {
     //---------------Set up test pack-------------------
     string[] recipients = { "to", "to2" };
     EmailSender sender = new EmailSender(recipients, "from", "subject", "content", "attach");
     sender.SmtpServerHost = "testhost";
     //---------------Execute Test ----------------------
     try
     {
         sender.SendAuthenticated("username", "password");
         Assert.Fail("Expected to throw an FormatException");
     }
         //---------------Test Result -----------------------
     catch (FormatException ex)
     {
         StringAssert.Contains("The specified string is not in the form required for an e-mail address", ex.Message);
     }
 }
            private void EmailErrorClickHandler(object sender, EventArgs e)
            {
                try
                {
                        
                    string emailTo = GlobalRegistry.Settings.GetString("EMAIL_TO");
                    string[] emailAddresses = emailTo.Split(new char[] { ';' });
                    string emailFrom = GlobalRegistry.Settings.GetString("EMAIL_FROM");

                    string emailContent = ExceptionUtilities.GetExceptionString(_exception, 0, true);

                    EmailSender emailSender = new EmailSender(emailAddresses, emailFrom, _exception.Source, emailContent, "");
                    //Todo : check Send Authenticated for security purposes?
                    emailSender.SmtpServerHost = GlobalRegistry.Settings.GetString("SMTP_SERVER");
                    string port = GlobalRegistry.Settings.GetString("SMTP_SERVER_PORT");
                    if (!String.IsNullOrEmpty(port))
                    {
                        emailSender.SmtpServerPort = Convert.ToInt32(port);
                    }
                    bool enableSSL = GlobalRegistry.Settings.GetBoolean("SMTP_ENABLE_SSL");
                    emailSender.EnableSSL = enableSSL;
                    //string authUsername = GlobalRegistry.Settings.GetString("SMTP_AUTH_USERNAME");
                    //string authPassword = GlobalRegistry.Settings.GetString("SMTP_AUTH_PASSWORD");
                    //if (!String.IsNullOrEmpty(authPassword))
                    //{
                    //    authPassword = Encryption.Decrypt(authPassword);
                    //}
                    //if (!String.IsNullOrEmpty(authUsername))
                    //{
                    //    emailSender.SendAuthenticated(authUsername, authPassword);
                    //}
                    //else
                    //{
                    emailSender.Send();
                    //}
                }
                catch(Exception ex)
                {
                    MessageBox.Show("The error message was not sent due to the following error : " + Environment.NewLine + ex.Message);
                }
            }