public void ReceiveMessages()
        {
            try
            {
                Pop3Connection connection = new Pop3Connection();

                //IPHostEntry hostInfo = Dns.GetHostEntry(Owner.Server);
                IPAddress[] addresses = Dns.GetHostAddresses(Owner.Server);

                IPEndPoint pop3ServerEndPoint = new IPEndPoint(addresses[0], Owner.Port);

                if (this.Owner.SecureConnectionType == Pop3SecureConnectionType.Ssl)
                {
                    connection.OpenSsl(pop3ServerEndPoint, Owner.Server);
                }
                else
                {
                    connection.Open(pop3ServerEndPoint);
                }

                if (this.Owner.SecureConnectionType == Pop3SecureConnectionType.Tls)
                {
                    connection.Stls(Owner.Server);
                }

                connection.User(Owner.Login);
                connection.Pass(Owner.Pass);

                Pop3Stat stat = connection.Stat();

                EMailRouterPop3Box.UpdateStatistic(this.Owner.EMailRouterPop3BoxId,
                    true,
                    string.Empty, stat.MessageCout);

                if(stat.MessageCout > 0)
                {
                    // Step 3. Request uidl.
                    Pop3UIDInfoList uidList = connection.Uidl();

                    foreach (Pop3UIDInfo uidItem in uidList)
                    {
                        try
                        {
                            // Step 4. Request message.
                            Pop3Message msg = connection.Retr(uidItem.ID);

                            // Step 5. Process message.
                            RaiseNewMessageEvent(msg);

                            // Step 6. Delete message from server.
                            connection.Dele(uidItem.ID);
                        }
                        catch (Exception  ex)
                        {
                            if(RaiseErrorEvent(ex))
                                throw;
                        }
                    }
                }

                connection.Quit();
            }
            catch(Exception ex)
            {
                if(RaiseErrorEvent(ex))
                    throw;
            }
        }
Beispiel #2
0
        public static Pop3SettingsResult CheckSettings(string Server, int Port, string User, string Password, Pop3SecureConnectionType SecureConnectionType)
        {
            string strEMailHost = Server;
            int iEMailPort = Port;
            string strEMailUser = User;
            string strEMailPassword = Password;

            Pop3SettingsResult retVal = Pop3SettingsResult.None;

            try
            {
                //IPHostEntry hostInfo = Dns.GetHostEntry(strEMailHost);
                IPAddress[] addresses = Dns.GetHostAddresses(strEMailHost);

                if (addresses.Length > 0)
                {
                    IPEndPoint pop3ServerEndPoint = new IPEndPoint(addresses[0], iEMailPort);

                    Pop3Connection pop3Connection = new Pop3Connection();

                    if (SecureConnectionType == Pop3SecureConnectionType.Ssl)
                    {
                        pop3Connection.OpenSsl(pop3ServerEndPoint, Server);
                    }
                    else
                    {
                        pop3Connection.Open(pop3ServerEndPoint);
                    }

                    if (SecureConnectionType == Pop3SecureConnectionType.Tls)
                    {
                        pop3Connection.Stls(Server);
                    }

                    retVal |= Pop3SettingsResult.ServerName;

                    try
                    {
                        pop3Connection.User(strEMailUser);
                        retVal |= Pop3SettingsResult.Pop3User;

                        pop3Connection.Pass(strEMailPassword);
                        retVal |= Pop3SettingsResult.Pop3Password;

                        Pop3Stat stat = pop3Connection.Stat();
                    }
                    finally
                    {
                        pop3Connection.Quit();
                    }
                }
            }
            catch (Exception ex)
            {
                string strErrMsg = ex.Message;
            }

            return retVal;
        }