Beispiel #1
0
        public static void TestSmtpServer(string server, int port, string username, string password)
        {
            if (_stateActiveMail == StateLibraryActiveMail.notfound)
            {
                PageActiveMailNotFound activeMailNotFoundDlg = new PageActiveMailNotFound();
                activeMailNotFoundDlg.ShowDialog();
                return;
            }

            try
            {
                Object smtpClient = Activator.CreateInstance(_activeSmtp.GetType("ActiveUp.Net.Mail.SmtpClient", true));
                smtpClient.GetType().GetMethod("Connect", new Type[] { Type.GetType("System.String"), Type.GetType("System.Int32") }).Invoke(smtpClient, new object[] { server, port });

                if (username.Trim() != "")
                {
                    try
                    {
                        smtpClient.GetType().GetMethod("Ehlo", new Type[] { Type.GetType("System.String") }).Invoke(smtpClient, new object[] { "" });
                    }

                    catch
                    {
                        smtpClient.GetType().GetMethod("Helo", new Type[] { Type.GetType("System.String") }).Invoke(smtpClient, new object[] { "" });
                    }

                    object SASLmechanism = (Enum)(_activeCommon.CreateInstance("ActiveUp.Net.Mail.SaslMechanism"));
                    SASLmechanism = (Enum)(Enum.Parse(SASLmechanism.GetType(), "Login"));
                    smtpClient.GetType().GetMethod("Authenticate", new Type[] { Type.GetType("System.String"), Type.GetType("System.String"), _activeSmtp.GetType("ActiveUp.Net.Mail.SaslMechanism", true) }).Invoke(smtpClient, new object[] { username, password, SASLmechanism });
                }

                smtpClient.GetType().GetMethod("Disconnect", new Type[] {}).Invoke(smtpClient, null);

                MessageBox.Show("All the parameters of the smtp server works", "Test successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    MessageBox.Show(ex.InnerException.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
		public static void TestSmtpServer(string server, int port, string username, string password)
		{
			if (_stateActiveMail == StateLibraryActiveMail.notfound)
			{
				PageActiveMailNotFound activeMailNotFoundDlg = new PageActiveMailNotFound();
				activeMailNotFoundDlg.ShowDialog();
				return;
			}

			try
			{
				Object smtpClient = Activator.CreateInstance(_activeSmtp.GetType("ActiveUp.Net.Mail.SmtpClient",true));	
				smtpClient.GetType().GetMethod("Connect", new Type[] {Type.GetType("System.String"), Type.GetType("System.Int32")}).Invoke(smtpClient,new object[] {server,port});
				
				if (username.Trim() != "")
				{
					try
					{
						smtpClient.GetType().GetMethod("Ehlo",new Type[] {Type.GetType("System.String")}).Invoke(smtpClient,new object[] {""});
					}

					catch
					{
						smtpClient.GetType().GetMethod("Helo",new Type[] {Type.GetType("System.String")}).Invoke(smtpClient,new object[] {""});
					}

					object SASLmechanism = (Enum)(_activeCommon.CreateInstance("ActiveUp.Net.Mail.SaslMechanism"));
					SASLmechanism = (Enum)(Enum.Parse(SASLmechanism.GetType(),"Login"));
					smtpClient.GetType().GetMethod("Authenticate", new Type[] {Type.GetType("System.String"),Type.GetType("System.String"),_activeSmtp.GetType("ActiveUp.Net.Mail.SaslMechanism",true)}).Invoke(smtpClient,new object[] {username,password,SASLmechanism});

				}

				smtpClient.GetType().GetMethod("Disconnect", new Type[] {}).Invoke(smtpClient,null);

				MessageBox.Show("All the parameters of the smtp server works","Test successful",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}

			catch(Exception ex)
			{
				if (ex.InnerException != null)
				MessageBox.Show(ex.InnerException.Message,"Test failed",MessageBoxButtons.OK,MessageBoxIcon.Error);
				else
				MessageBox.Show(ex.Message,"Test failed",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}