Пример #1
0
        /// <summary>
        /// Sends the message using the specified host as dns server on the specified port.
        /// </summary>
        /// <param name="host">The host to be used.</param>
        /// <param name="port">The port to be used.</param>
        /// <example>
        /// <code>
        /// C#
        ///
        /// SmtpMessage message = new SmtpMessage();
        /// message.Subject = "Test";
        /// message.From = new Address("*****@*****.**","John Doe");
        /// message.To.Add("*****@*****.**","Mike Johns");
        /// message.BodyText.Text = "Hello this is a test!";
        ///
        /// message.DirectSend("ns1.dnsserver.com",53);
        ///
        /// VB.NET
        ///
        /// Dim message As New SmtpMessage
        /// message.Subject = "Test"
        /// message.From = New Address("*****@*****.**","John Doe")
        /// message.To.Add("*****@*****.**","Mike Johns")
        /// message.BodyText.Text = "Hello this is a test!"
        ///
        /// message.DirectSend("ns1.dnsserver.com",53)
        ///
        /// JScript.NET
        ///
        /// var message:SmtpMessage = new SmtpMessage();
        /// message.Subject = "Test";
        /// message.From = new Address("*****@*****.**","John Doe");
        /// message.To.Add("*****@*****.**","Mike Johns");
        /// message.BodyText.Text = "Hello this is a test!";
        ///
        /// message.DirectSend("ns1.dnsserver.com",53);
        /// </code>
        /// </example>
        public string DirectSend(string dnsHost, int dnsPort)
        {
            ServerCollection servers = new ServerCollection();

            servers.Add(dnsHost, dnsPort);
            return(DirectSend(servers));
        }
Пример #2
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <param name="dnsServerHost">Name Server to be used for MX records search.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(Address address, string dnsServerHost)
        {
            ServerCollection servers = new ServerCollection();

            servers.Add(dnsServerHost, 53);
            return(Validate(address.Email, servers));
        }
Пример #3
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(string address, ServerCollection dnsServers)
        {
            if (!ValidateSyntax(address))
            {
                return(false);
            }
            else
            {
                string     domain = address.Split('@')[1];
                bool       result;
                SmtpClient smtp = new SmtpClient();
                smtp.SendTimeout    = 15;
                smtp.ReceiveTimeout = 15;

                MxRecordCollection mxRecords = new MxRecordCollection();
                try
                {
#if !PocketPC
                    mxRecords = GetMxRecords(domain, dnsServers);
#else
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
#endif
                }
                catch
                {
                    new Exception("Can't connect to DNS server.");
                }
                smtp.Connect(mxRecords.GetPrefered().Exchange);
                try
                {
                    smtp.Ehlo(System.Net.Dns.GetHostName());
                }
                catch
                {
                    smtp.Helo(System.Net.Dns.GetHostName());
                }
                if (smtp.Verify(address))
                {
                    result = true;
                }
                else
                {
                    try
                    {
                        //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                        //smtp.MailFrom("*****@*****.**");
                        smtp.MailFrom("postmaster@" + domain);
                        smtp.RcptTo(address);
                        result = true;
                    }
                    catch
                    {
                        result = false;
                    }
                }
                smtp.Disconnect();
                return(result);
            }
        }
Пример #4
0
        /// <summary>
        /// Allows the developer to add a collection of Server objects in another one.
        /// </summary>
        /// <param name="first">The first collection.</param>
        /// <param name="second">The second collection.</param>
        /// <returns>The concacened collection.</returns>
        public static ServerCollection operator +(ServerCollection first, ServerCollection second)
        {
            ServerCollection newServers = first;

            foreach (Server server in second)
            {
                newServers.Add(server);
            }

            return(newServers);
        }
Пример #5
0
        public void Enviar()
        {
            ServerCollection servers = new ServerCollection();
            Server Nlayer = new Server();
            Message message = new Message();
            MimeBody mimeBody = new MimeBody(BodyFormat.Html);
            AddressCollection destinos = new AddressCollection();

            Nlayer.Host = "mail.softwareNlayer.com";
            Nlayer.Password = "******";
            Nlayer.Port = 25;
            Nlayer.Username = "******";

            servers.Add(Nlayer);

            if (_destinos != null)
            {
                foreach (string destino in _destinos)
                {
                    destinos.Add(new Address(destino));
                }
            }

            if (_adjuntos != null)
            {
                foreach (string adjunto in _adjuntos)
                {
                    message.Attachments.Add(adjunto, false);
                }
            }

            mimeBody.Text = _mensaje;

            message.BodyHtml = mimeBody;
            message.Date = DateTime.Now;
            message.From = new Address("*****@*****.**");
            message.Organization = "Nlayer Software";
            message.Priority = MessagePriority.Normal;
            message.To = destinos;
            message.Subject = _asunto;

            AsyncCallback beginCallback = IniciaEnvio;
            SmtpClient.BeginSend(message, servers, beginCallback);
        }
        private void _bSendMessage_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Creating message.");

            // We create the message object
            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();

            // We assign the sender email
            message.From.Email = this._tbFromEmail.Text;

            // We assign the recipient email
            message.To.Add(this._tbToEmail.Text);

            // We assign the subject
            message.Subject = this._tbSubject.Text;

            // We assign the body text
            message.BodyText.Text = this._tbBodyText.Text;

            ServerCollection smtpServers = new ServerCollection();
            smtpServers.Add(this._tbMainSmtpServer.Text);
            smtpServers.Add(this._tbBackupSmtpServer.Text);

            // We send the email using the specified SMTP server
            this.AddLogEntry("Sending message.");

            try
            {
                message.Send(smtpServers);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
Пример #7
0
        /// <summary>
        /// Get the MX records for the specified domain name using the system configuration.
        /// </summary>
        /// <param name="address">The domain name.</param>
        /// <param name="dnsServers">Servers to be used for MX records search.</param>
        /// <returns>A collection of Mx Records.</returns>
        public static ActiveUp.Net.Mail.MxRecordCollection GetMxRecords(string address,
                                                                        ActiveUp.Net.Mail.ServerCollection dnsServers, int timeout)
        {
            if (dnsServers == null)
            {
                dnsServers = new ServerCollection();
            }

            if (dnsServers.Count == 0)
            {
#if !PocketPC
                NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in adapters)
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties();
                    if (properties.DnsAddresses.Count > 0)
                    {
                        foreach (IPAddress ipAddress in properties.DnsAddresses)
                        {
                            dnsServers.Add(ipAddress.ToString(), 53);
                        }
                    }
                }
#endif
            }

            foreach (ActiveUp.Net.Mail.Server server in dnsServers)
            {
                try
                {
                    return(GetMxRecords(address, server.Host, server.Port, timeout));
                }
                catch
                {
                    ActiveUp.Net.Mail.Logger.AddEntry("Can't connect to " + server.Host + ":" + server.Port, 0);
                }
            }

            return(GetMxRecords(address));

            //ActiveUp.Net.Mail.Logger.AddEntry("Can't connect to any of the specified DNS servers.", 0);
        }
Пример #8
0
 /// <summary>
 /// Validates syntax and existence of the given address.
 /// </summary>
 /// <param name="address">The address to be validated.</param>
 /// <param name="dnsServerHost">Name Server to be used for MX records search.</param>
 /// <returns>True if the address is valid, otherwise false.</returns>
 public static bool Validate(Address address, string dnsServerHost)
 {
     ActiveUp.Net.Mail.ServerCollection servers = new ActiveUp.Net.Mail.ServerCollection();
     servers.Add(dnsServerHost, 53);
     return(ActiveUp.Net.Mail.SmtpValidator.Validate(address.Email, servers));
 }
Пример #9
0
 public static IAsyncResult BeginValidate(Address address, ServerCollection dnsServers, AsyncCallback callback)
 {
     SmtpValidator._delegateValidateAddressServers = SmtpValidator.Validate;
     return SmtpValidator._delegateValidateAddressServers.BeginInvoke(address, dnsServers, callback, SmtpValidator._delegateValidateAddressServers);
 }
Пример #10
0
 public static IAsyncResult BeginValidate(string address, ServerCollection servers, AsyncCallback callback)
 {
     SmtpValidator._delegateValidateStringServers = SmtpValidator.Validate;
     return SmtpValidator._delegateValidateStringServers.BeginInvoke(address, servers, callback, SmtpValidator._delegateValidateStringServers);
 }
Пример #11
0
		            /// <summary>
		            /// Sends all messages using the specified host and port as the dns server.
		            /// </summary>
		            /// <param name="messages">The message collection to be sent.</param>
		            /// <param name="dnsHost">Address of the server to be used.</param>
		            /// <param name="dnsPort">Port to be used.</param>
		            /// <returns>Amount of messages successfully sent.</returns>
		            /// <example>
		            /// <code>
		            /// C#
		            /// 
		            /// Message message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// Message message1 = new Message();
		            /// message1.Subject = "Hey David!";
		            /// message1.From = New Address("*****@*****.**","John Doe");
		            /// message1.To.Add("*****@*****.**","David Clark");
		            /// message1.BodyText.Text = "How you doing ?";
		            /// 
		            /// MessageCollection messages = new MessageCollection();
		            /// messages.Add(message);
		            /// messages.Add(message1);
		            /// 
		            /// SmtpClient.DirectSend(messages,"ns1.dnsserver.com",53);
		            /// 
		            /// VB.NET
		            /// 
		            /// Dim message As New Message
		            /// message.Subject = "Test"
		            /// message.From = New Address("*****@*****.**","John Doe")
		            /// message.To.Add("*****@*****.**","Mike Johns")
		            /// message.BodyText.Text = "Hello this is a test!"
		            /// 
		            /// Dim message1 As New Message
		            /// message1.Subject = "Hey David!"
		            /// message1.From = New Address("*****@*****.**","John Doe")
		            /// message1.To.Add("*****@*****.**","David Clark")
		            /// message1.BodyText.Text = "How you doing ?"
		            /// 
		            /// Dim messages As New MessageCollection
		            /// messages.Add(message)
		            /// messages.Add(message1)
		            /// 
		            /// SmtpClient.DirectSend(messages,"ns1.dnsserver.com",53)
		            /// 
		            /// JScript.NET
		            /// 
		            /// var message:Message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// var message1:Message = new Message();
		            /// message1.Subject = "Hey David!";
		            /// message1.From = New Address("*****@*****.**","John Doe");
		            /// message1.To.Add("*****@*****.**","David Clark");
		            /// message1.BodyText.Text = "How you doing ?";
		            /// 
		            /// var messages:MessageCollection = new MessageCollection();
		            /// messages.Add(message);
		            /// messages.Add(message1);
		            /// 
		            /// SmtpClient.DirectSend(messages,"ns1.dnsserver.com",53);
		            /// </code>
		            /// </example>
		            public static int DirectSendCollection(MessageCollection messages, string dnsHost, int dnsPort)
		            {
			            ActiveUp.Net.Mail.ServerCollection servers = new ActiveUp.Net.Mail.ServerCollection();
			            servers.Add(dnsHost, dnsPort);
			            return DirectSendCollection(messages, servers);
		            }
Пример #12
0
		            /// <summary>
		            /// Sends the message using the specified host as mail exchange server.
		            /// </summary>
		            /// <param name="message">The message to be sent.</param>
		            /// <param name="servers">Servers to be used to send the message (in preference order).</param>
		            /// <example>
		            /// <code>
		            /// C#
		            /// 
		            /// Message message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// ServerCollection servers = new ServerCollection();
		            /// servers.Add("mail.myhost.com",25);
		            /// servers.Add("mail2.myhost.com",25);
		            /// 
		            /// SmtpClient.Send(message,servers);
		            /// 
		            /// VB.NET
		            /// 
		            /// Dim message As New Message
		            /// message.Subject = "Test"
		            /// message.From = New Address("*****@*****.**","John Doe")
		            /// message.To.Add("*****@*****.**","Mike Johns")
		            /// message.BodyText.Text = "Hello this is a test!"
		            /// 
		            /// Dim servers As New ServerCollection
		            /// servers.Add("mail.myhost.com",25)
		            /// servers.Add("mail2.myhost.com",25)
		            /// 
		            /// SmtpClient.Send(message,servers)
		            /// 
		            /// JScript.NET
		            /// 
		            /// var message:Message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// var servers:ServerCollection = new ServerCollection();
		            /// servers.Add("mail.myhost.com",25);
		            /// servers.Add("mail2.myhost.com",25);
		            /// 
		            /// SmtpClient.Send(message,servers);
		            /// </code>
		            /// </example>
		            public static bool Send(Message message, ServerCollection servers, out string serverMessage)
		            {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

			            serverMessage = string.Empty;
			            ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
			            bool messageSent = false;
			            for(int i=0;i<servers.Count;i++)
			            {
				            try
				            {
                                if (servers[i].ServerEncryptionType != EncryptionType.None)
                                {
#if !PocketPC
                                    smtp.ConnectSsl(servers[i].Host,servers[i].Port);
#else
                                    smtp.Connect(servers[i].Host, servers[i].Port);
#endif
                                }else {
					                smtp.Connect(servers[i].Host,servers[i].Port);
                                }
					            try
					            {
						            smtp.Ehlo(System.Net.Dns.GetHostName());
					            }
					            catch
					            {
						            smtp.Helo(System.Net.Dns.GetHostName());
					            }
					            if(servers[i].Username!=null && servers[i].Username.Length>0 && servers[i].Password!=null && servers[i].Password.Length>0) smtp.Authenticate(servers[i].Username,servers[i].Password,SaslMechanism.Login);
					            if(message.From.Email!=string.Empty) smtp.MailFrom(message.From);
					            else smtp.MailFrom(message.Sender);
					            smtp.RcptTo(message.To);
					            smtp.RcptTo(message.Cc);
					            smtp.RcptTo(message.Bcc);
					            serverMessage = smtp.Data(message.ToMimeString());//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
					            smtp.Disconnect();
					            messageSent = true;
					            break;
				            }
				            catch
				            {
					            continue;
				            }
			            }

			            return messageSent;
		            }
Пример #13
0
 public static IAsyncResult BeginFilter(AddressCollection addresses, ServerCollection dnsServers, AsyncCallback callback)
 {
     _delegateFilterServers = Filter;
     return(_delegateFilterServers.BeginInvoke(addresses, dnsServers, callback, _delegateFilterServers));
 }
Пример #14
0
		            /// <summary>
		            /// Sends all messages using the specified host as the DNS server.
		            /// </summary>
		            /// <param name="dnsServers">Servers to be used to send the message (in preference order).</param>
		            /// <returns>Amount of messages successfully sent.</returns>
		            /// <example>
		            /// <code>
		            /// C#
		            /// 
		            /// Message message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// Message message1 = new Message();
		            /// message1.Subject = "Hey David!";
		            /// message1.From = New Address("*****@*****.**","John Doe");
		            /// message1.To.Add("*****@*****.**","David Clark");
		            /// message1.BodyText.Text = "How you doing ?";
		            /// 
		            /// MessageCollection messages = new MessageCollection();
		            /// messages.Add(message);
		            /// messages.Add(message1);
		            /// 
		            /// ServerCollection servers = new ServerCollection();
		            /// servers.Add("ns1.dnsserver.com",53);
		            /// servers.Add("ns2.dnsserver.com",53);
		            /// 
		            /// SmtpClient.DirectSend(messages,servers);
		            /// 
		            /// VB.NET
		            /// 
		            /// Dim message As New Message
		            /// message.Subject = "Test"
		            /// message.From = New Address("*****@*****.**","John Doe")
		            /// message.To.Add("*****@*****.**","Mike Johns")
		            /// message.BodyText.Text = "Hello this is a test!"
		            /// 
		            /// Dim message1 As New Message
		            /// message1.Subject = "Hey David!"
		            /// message1.From = New Address("*****@*****.**","John Doe")
		            /// message1.To.Add("*****@*****.**","David Clark")
		            /// message1.BodyText.Text = "How you doing ?"
		            /// 
		            /// Dim messages As New MessageCollection
		            /// messages.Add(message)
		            /// messages.Add(message1)
		            /// 
		            /// Dim servers As New ServerCollection
		            /// servers.Add("ns1.dnsserver.com",53)
		            /// servers.Add("ns2.dnsserver.com",53)
		            /// 
		            /// SmtpClient.DirectSend(messages,servers)
		            /// 
		            /// JScript.NET
		            /// 
		            /// var message:Message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// var message1:Message = new Message();
		            /// message1.Subject = "Hey David!";
		            /// message1.From = New Address("*****@*****.**","John Doe");
		            /// message1.To.Add("*****@*****.**","David Clark");
		            /// message1.BodyText.Text = "How you doing ?";
		            /// 
		            /// var messages:MessageCollection = new MessageCollection();
		            /// messages.Add(message);
		            /// messages.Add(message1);
		            /// 
		            /// var servers:ServerCollection = new ServerCollection();
		            /// servers.Add("ns1.dnsserver.com",53);
		            /// servers.Add("ns2.dnsserver.com",53);
		            /// 
		            /// SmtpClient.DirectSend(messages,servers);
		            /// </code>
		            /// </example>
		            public static int DirectSendCollection(MessageCollection messages, ServerCollection dnsServers)
		            {
			            int sent=0;
			            foreach(ActiveUp.Net.Mail.Message message in messages)
			            {
				            ActiveUp.Net.Mail.SmtpClient.DirectSend(message);
				            sent++;
			            }
			            return sent;
		            }
Пример #15
0
 /// <summary>
 /// Sends the message using the specified host as dns server on the specified port.
 /// </summary>
 /// <param name="host">The host to be used.</param>
 /// <param name="port">The port to be used.</param>
 /// <example>
 /// <code>
 /// C#
 ///
 /// SmtpMessage message = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 ///
 /// message.DirectSend("ns1.dnsserver.com",53);
 ///
 /// VB.NET
 ///
 /// Dim message As New SmtpMessage
 /// message.Subject = "Test"
 /// message.From = New Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.BodyText.Text = "Hello this is a test!"
 ///
 /// message.DirectSend("ns1.dnsserver.com",53)
 ///
 /// JScript.NET
 ///
 /// var message:SmtpMessage = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 ///
 /// message.DirectSend("ns1.dnsserver.com",53);
 /// </code>
 /// </example>
 public string DirectSend(string dnsHost, int dnsPort)
 {
     ActiveUp.Net.Mail.ServerCollection servers = new ActiveUp.Net.Mail.ServerCollection();
     servers.Add(dnsHost, dnsPort);
     return(DirectSend(servers));
 }
Пример #16
0
 /// <summary>
 /// Sends the message using the specified DNS servers to get mail exchange servers addresses.
 /// </summary>
 /// <param name="dnsServers">Servers to be used (in preference order).</param>
 /// <example>
 /// <code>
 /// C#
 ///
 /// SmtpMessage message = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 ///
 /// ServerCollection servers = new ServerCollection();
 /// servers.Add("ns1.dnsserver.com",53);
 /// servers.Add("ns2.dnsserver.com",53);
 ///
 /// message.DirectSend(servers);
 ///
 /// VB.NET
 ///
 /// Dim message As New SmtpMessage
 /// message.Subject = "Test"
 /// message.From = New Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.BodyText.Text = "Hello this is a test!"
 ///
 /// Dim servers As New ServerCollection
 /// servers.Add("ns1.dnsserver.com",53)
 /// servers.Add("ns2.dnsserver.com",53)
 ///
 /// message.DirectSend(servers)
 ///
 /// JScript.NET
 ///
 /// var message:SmtpMessage = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 ///
 /// var servers:ServerCollection = new ServerCollection();
 /// servers.Add("ns1.dnsserver.com",53);
 /// servers.Add("ns2.dnsserver.com",53);
 ///
 /// message.DirectSend(servers);
 /// </code>
 /// </example>
 public string DirectSend(ServerCollection dnsServers)
 {
     return(SmtpClient.DirectSend(this, dnsServers));
 }
Пример #17
0
        public static IAsyncResult BeginFilter(AddressCollection addresses, ServerCollection dnsServers, AsyncCallback callback)
        {
            SmtpValidator._delegateFilterServers = SmtpValidator.Filter;
            return SmtpValidator._delegateFilterServers.BeginInvoke(addresses, dnsServers, callback, SmtpValidator._delegateFilterServers);

        }
Пример #18
0
 /// <summary>
 /// Sends the message using the specified host as the mail exchange server.
 /// </summary>
 /// <param name="servers">Servers to be used to send the message (in preference order).</param>
 /// <example>
 /// <code>
 /// C#
 ///
 ///SmtpMessage message = new SmtpMessage();
 ///message.From = new Address("*****@*****.**","John Doe");
 ///message.To.Add("*****@*****.**","Mike Johns");
 ///message.Subject = "hey!";
 ///message.Attachments.Add("C:\\myfile.doc");
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John.";
 ///
 ///ServerCollection servers = new ServerCollection();
 ///servers.Add("mail.myhost.com",25);
 ///servers.Add("mail2.myhost.com",25);
 ///
 ///message.Send(servers);
 ///
 /// VB.NET
 ///
 ///Dim message As New SmtpMessage
 ///message.From = new Address("*****@*****.**","John Doe")
 ///message.To.Add("*****@*****.**","Mike Johns")
 ///message.Subject = "hey!"
 ///message.Attachments.Add("C:\myfile.doc")
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 ///
 ///Dim servers As New ServerCollection
 ///servers.Add("mail.myhost.com",25)
 ///servers.Add("mail2.myhost.com",25)
 ///
 ///message.Send(servers)
 ///
 /// JScript.NET
 ///
 ///var message:SmtpMessage = new SmtpMessage();
 ///message.From = new Address("*****@*****.**","John Doe")
 ///message.To.Add("*****@*****.**","Mike Johns");
 ///message.Subject = "hey!";
 ///message.Attachments.Add("C:\\myfile.doc");
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 ///
 ///var servers:ServerCollection = new ServerCollection();
 ///servers.Add("mail.myhost.com",25);
 ///servers.Add("mail2.myhost.com",25);
 ///
 ///message.Send(servers);
 /// </code>
 /// </example>
 public void Send(ServerCollection servers)
 {
     //CheckBuiltMimePartTree();
     SmtpClient.Send(this, servers);
 }
Пример #19
0
        /// <summary>
        /// Validates syntax and existence of the given address and returns valid addresses.
        /// </summary>
        /// <param name="addresses">The collection to be filtered.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>A collection containing the valid addresses.</returns>
        public static AddressCollection Filter(AddressCollection addresses, ServerCollection dnsServers)
        {
            ActiveUp.Net.Mail.AddressCollection valids = new ActiveUp.Net.Mail.AddressCollection();
            ActiveUp.Net.Mail.AddressCollection valids1 = new ActiveUp.Net.Mail.AddressCollection();
            System.Collections.Specialized.HybridDictionary ads = new System.Collections.Specialized.HybridDictionary();
            for (int i = 0; i < addresses.Count; i++)
                if (ActiveUp.Net.Mail.Validator.ValidateSyntax(addresses[i].Email)) valids.Add(addresses[i]);
#if !PocketPC
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count }, new int[] { 0 });
            System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count }, new int[] { 0 });
#else
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count });
            System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count });
#endif
            for (int i = 0; i < valids.Count; i++)
            {
                domains.SetValue(valids[i].Email.Split('@')[1], i);
                adds.SetValue(valids[i], i);
            }
            System.Array.Sort(domains, adds, null);
            string currentDomain = "";
            string address = "";
            ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
            bool isConnected = false;
            for (int i = 0; i < adds.Length; i++)
            {
                address = ((ActiveUp.Net.Mail.Address)adds.GetValue(i)).Email;
                if (((string)domains.GetValue(i)) == currentDomain)
                {
                    if (!smtp.Verify(address))
                    {
                        try
                        {
                            //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                            //smtp.MailFrom("postmaster@"+currentDomain);
                            smtp.RcptTo(address);
                            valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                        }
                        catch
                        {

                        }
                    }
                    else valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                }
                else
                {
                    currentDomain = (string)domains.GetValue(i);
                    try
                    {
                        if (isConnected == true)
                        {
                            isConnected = false;
                            smtp.Disconnect();
                            smtp = new ActiveUp.Net.Mail.SmtpClient();
                        }

                        smtp.Connect(ActiveUp.Net.Mail.Validator.GetMxRecords(currentDomain, dnsServers).GetPrefered().Exchange);
                        isConnected = true;
                        try
                        {
                            smtp.Ehlo(System.Net.Dns.GetHostName());
                        }
                        catch
                        {
                            smtp.Helo(System.Net.Dns.GetHostName());
                        }
                        if (!smtp.Verify(address))
                        {
                            try
                            {
                                //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                                //smtp.MailFrom("*****@*****.**");
                                smtp.MailFrom("postmaster@" + currentDomain);
                                smtp.RcptTo(address);
                                valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                            }
                            catch
                            {

                            }
                        }
                        else valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                    }
                    catch
                    {

                    }
                }
            }
            if (isConnected == true)
                smtp.Disconnect();
            return valids1;
        }
Пример #20
0
 public static IAsyncResult BeginGetInvalidAddresses(AddressCollection addresses, ServerCollection dnsServers, AsyncCallback callback)
 {
     SmtpValidator._delegateGetInvalidAddressesServers = SmtpValidator.GetInvalidAddresses;
     return SmtpValidator._delegateGetInvalidAddressesServers.BeginInvoke(addresses, dnsServers, callback, SmtpValidator._delegateGetInvalidAddressesServers);
 }
Пример #21
0
 /// <summary>
 /// Validates syntax and existence of the given address.
 /// </summary>
 /// <param name="address">The address to be validated.</param>
 /// <param name="dnsServerHost">Name Server to be used for MX records search.</param>
 /// <returns>True if the address is valid, otherwise false.</returns>
 public static bool Validate(Address address, string dnsServerHost)
 {
     ActiveUp.Net.Mail.ServerCollection servers = new ActiveUp.Net.Mail.ServerCollection();
     servers.Add(dnsServerHost, 53);
     return ActiveUp.Net.Mail.SmtpValidator.Validate(address.Email, servers);
 }
Пример #22
0
 public static IAsyncResult BeginGetInvalidAddresses(AddressCollection addresses, ServerCollection dnsServers, AsyncCallback callback)
 {
     _delegateGetInvalidAddressesServers = GetInvalidAddresses;
     return(_delegateGetInvalidAddressesServers.BeginInvoke(addresses, dnsServers, callback, _delegateGetInvalidAddressesServers));
 }
Пример #23
0
 public IAsyncResult BeginDirectSend(ServerCollection dnsServers, AsyncCallback callback)
 {
     return(SmtpClient.BeginDirectSend(this, dnsServers, callback));
 }
Пример #24
0
        /// <summary>
        /// Validates syntax and existence of the given address and returns valid addresses.
        /// </summary>
        /// <param name="addresses">The collection to be filtered.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>A collection containing the valid addresses.</returns>
        public static AddressCollection Filter(AddressCollection addresses, ServerCollection dnsServers)
        {
            AddressCollection valids  = new AddressCollection();
            AddressCollection valids1 = new AddressCollection();

            System.Collections.Specialized.HybridDictionary ads = new System.Collections.Specialized.HybridDictionary();
            for (int i = 0; i < addresses.Count; i++)
            {
                if (ValidateSyntax(addresses[i].Email))
                {
                    valids.Add(addresses[i]);
                }
            }
#if !PocketPC
            Array domains = Array.CreateInstance(typeof(string), new int[] { valids.Count }, new int[] { 0 });
            Array adds    = Array.CreateInstance(typeof(Address), new int[] { valids.Count }, new int[] { 0 });
#else
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count });
            System.Array adds    = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count });
#endif
            for (int i = 0; i < valids.Count; i++)
            {
                domains.SetValue(valids[i].Email.Split('@')[1], i);
                adds.SetValue(valids[i], i);
            }
            Array.Sort(domains, adds, null);
            string     currentDomain = "";
            string     address       = "";
            SmtpClient smtp          = new SmtpClient();
            bool       isConnected   = false;
            for (int i = 0; i < adds.Length; i++)
            {
                address = ((Address)adds.GetValue(i)).Email;
                if (((string)domains.GetValue(i)) == currentDomain)
                {
                    if (!smtp.Verify(address))
                    {
                        try
                        {
                            //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                            //smtp.MailFrom("postmaster@"+currentDomain);
                            smtp.RcptTo(address);
                            valids1.Add((Address)adds.GetValue(i));
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        valids1.Add((Address)adds.GetValue(i));
                    }
                }
                else
                {
                    currentDomain = (string)domains.GetValue(i);
                    try
                    {
                        if (isConnected == true)
                        {
                            isConnected = false;
                            smtp.Disconnect();
                            smtp = new SmtpClient();
                        }

                        smtp.Connect(GetMxRecords(currentDomain, dnsServers).GetPrefered().Exchange);
                        isConnected = true;
                        try
                        {
                            smtp.Ehlo(System.Net.Dns.GetHostName());
                        }
                        catch
                        {
                            smtp.Helo(System.Net.Dns.GetHostName());
                        }
                        if (!smtp.Verify(address))
                        {
                            try
                            {
                                //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                                //smtp.MailFrom("*****@*****.**");
                                smtp.MailFrom("postmaster@" + currentDomain);
                                smtp.RcptTo(address);
                                valids1.Add((Address)adds.GetValue(i));
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            valids1.Add((Address)adds.GetValue(i));
                        }
                    }
                    catch
                    {
                    }
                }
            }
            if (isConnected == true)
            {
                smtp.Disconnect();
            }
            return(valids1);
        }
Пример #25
0
		/// <summary>
		/// Get the MX records for the specified domain name using the system configuration.
		/// </summary>
		/// <param name="address">The domain name.</param>
		/// <param name="dnsServers">Servers to be used for MX records search.</param>
		/// <returns>A collection of Mx Records.</returns>
		public static ActiveUp.Net.Mail.MxRecordCollection GetMxRecords(string address, 
            ActiveUp.Net.Mail.ServerCollection dnsServers, int timeout)
		{
            if (dnsServers == null)
                dnsServers = new ServerCollection();

            if (dnsServers.Count == 0)
            {
#if !PocketPC
                NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in adapters)
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties();
                    if (properties.DnsAddresses.Count > 0)
                    {
                        foreach (IPAddress ipAddress in properties.DnsAddresses)
                            dnsServers.Add(ipAddress.ToString(), 53);
                    }
                }
#endif
            }

			foreach(ActiveUp.Net.Mail.Server server in dnsServers)
			{
				try
				{
					return GetMxRecords(address, server.Host, server.Port, timeout);
				}
				catch
				{
					ActiveUp.Net.Mail.Logger.AddEntry("Can't connect to " + server.Host + ":" + server.Port, 0);
				}
			}

		return GetMxRecords(address);

		//ActiveUp.Net.Mail.Logger.AddEntry("Can't connect to any of the specified DNS servers.", 0);
	}
Пример #26
0
		            /// <summary>
		            /// Sends the message using the specified DNS servers to get mail exchange servers addresses.
		            /// </summary>
		            /// <param name="message">The message to be sent.</param>
		            /// <param name="dnsServers">Servers to be used (in preference order).</param>
		            /// <example>
		            /// <code>
		            /// C#
		            /// 
		            /// Message message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// ServerCollection servers = new ServerCollection();
		            /// servers.Add("ns1.dnsserver.com",53);
		            /// servers.Add("ns2.dnsserver.com",53);
		            /// 
		            /// SmtpClient.DirectSend(message,servers);
		            /// 
		            /// VB.NET
		            /// 
		            /// Dim message As New Message
		            /// message.Subject = "Test"
		            /// message.From = New Address("*****@*****.**","John Doe")
		            /// message.To.Add("*****@*****.**","Mike Johns")
		            /// message.BodyText.Text = "Hello this is a test!"
		            /// 
		            /// Dim servers As New ServerCollection
		            /// servers.Add("ns1.dnsserver.com",53)
		            /// servers.Add("ns2.dnsserver.com",53)
		            /// 
		            /// SmtpClient.DirectSend(message,servers)
		            /// 
		            /// JScript.NET
		            /// 
		            /// var message:Message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// var servers:ServerCollection = new ServerCollection();
		            /// servers.Add("ns1.dnsserver.com",53);
		            /// servers.Add("ns2.dnsserver.com",53);
		            /// 
		            /// SmtpClient.DirectSend(message,servers);
		            /// </code>
		            /// </example>
		            public static string DirectSend(Message message, ServerCollection dnsServers)
		            {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

			            string email = (message.From.Name!="(unknown)") ? message.From.Email : message.Sender.Email;
			            int recipientCount = message.To.Count+message.Cc.Count+message.Bcc.Count;
#if !PocketPC
                        System.Array domains = System.Array.CreateInstance(typeof(string),new int[] {recipientCount},new int[] {0});
			            System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address),new int[] {recipientCount},new int[] {0});
#else
                        System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { recipientCount });
                        System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { recipientCount });
#endif
                        ActiveUp.Net.Mail.AddressCollection recipients = new ActiveUp.Net.Mail.AddressCollection();
			            recipients += message.To;
			            recipients += message.Cc;
			            recipients += message.Bcc;
			            for(int i=0;i<recipients.Count;i++)
			            {
				            if (ActiveUp.Net.Mail.Validator.ValidateSyntax(recipients[i].Email))
				            {
					            domains.SetValue(recipients[i].Email.Split('@')[1],i);
					            adds.SetValue(recipients[i],i);
				            }
			            }
			            System.Array.Sort(domains,adds,null);
			            string currentDomain = "";
			            string address = "";
			            string buf = "";
			            ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
			            for(int j=0;j<adds.Length;j++)
			            {
				            address = ((ActiveUp.Net.Mail.Address)adds.GetValue(j)).Email;
				            if(((string)domains.GetValue(j))==currentDomain)
				            {
					            smtp.RcptTo(address);
					            if(j==(adds.Length-1))
					            {
                                    smtp.Data(message.ToMimeString(true));//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
                                    smtp.Disconnect();
					            }
				            }
				            else
				            {
					            if(currentDomain!="")
					            {
						            smtp.Data(message.ToMimeString(true));//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
						            smtp.Disconnect();
						            smtp = new ActiveUp.Net.Mail.SmtpClient(); 
					            }
					            currentDomain = (string)domains.GetValue(j);				
					            buf += currentDomain+"|";

                                if (dnsServers == null || dnsServers.Count == 0)
                                {
                                    if (dnsServers == null)
                                        dnsServers = new ServerCollection();

                                    IList<IPAddress> machineDnsServers = DnsQuery.GetMachineDnsServers();
                                    foreach (IPAddress ipAddress in machineDnsServers)
                                        dnsServers.Add(ipAddress.ToString());
                                }
					            ActiveUp.Net.Mail.MxRecordCollection mxs = ActiveUp.Net.Mail.Validator.GetMxRecords(currentDomain, dnsServers);
					            if(mxs != null && mxs.Count>0) smtp.Connect(mxs.GetPrefered().Exchange);
					            else throw new ActiveUp.Net.Mail.SmtpException("No MX record found for the domain \""+currentDomain+"\". Check that the domain is correct and exists or specify a DNS server.");
					            try
					            {
						            smtp.Ehlo(System.Net.Dns.GetHostName());
					            }
					            catch
					            {
						            smtp.Helo(System.Net.Dns.GetHostName());
					            }
					            smtp.MailFrom(email);
					            smtp.RcptTo(address);
                                if (j == (adds.Length - 1))
                                {
                                    smtp.Data(message.ToMimeString(true));//,(message.Charset!=null ? message.Charset : "iso-8859-1"));					
                                    smtp.Disconnect();
                                }
				            }
				            //}
				            //catch(ActiveUp.Net.Mail.SmtpException ex) { throw ex; }
			            }
			            return buf;
                    }
Пример #27
0
                    /// <summary>
		            /// Sends all messages using the specified host.
		            /// </summary>
		            /// <param name="servers">Servers to be used to send the message (in preference order).</param>
		            /// <param name="messages">MessageCollection to be sent.</param>
		            /// <param name="errors">Reference to SmtpException object collection where errors occuring during the process will be stored.</param>
		            /// <returns>Amount of messages successfully sent.</returns>
		            /// <example>
		            /// <code>
		            /// C#
		            /// 
		            /// Message message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// Message message1 = new Message();
		            /// message1.Subject = "Hey David!";
		            /// message1.From = New Address("*****@*****.**","John Doe");
		            /// message1.To.Add("*****@*****.**","David Clark");
		            /// message1.BodyText.Text = "How you doing ?";
		            /// 
		            /// MessageCollection messages = new MessageCollection();
		            /// messages.Add(message);
		            /// messages.Add(message1);
		            /// 
		            /// ServerCollection servers = new ServerCollection();
		            /// servers.Add("mail.myhost.com",25);
		            /// servers.Add("mail2.myhost.com",25);
		            /// 
		            /// SmtpClient.Send(messages,servers,myErrorCollection);
		            /// 
		            /// VB.NET
		            /// 
		            /// Dim message As New Message
		            /// message.Subject = "Test"
		            /// message.From = New Address("*****@*****.**","John Doe")
		            /// message.To.Add("*****@*****.**","Mike Johns")
		            /// message.BodyText.Text = "Hello this is a test!"
		            /// 
		            /// Dim message1 As New Message
		            /// message1.Subject = "Hey David!"
		            /// message1.From = New Address("*****@*****.**","John Doe")
		            /// message1.To.Add("*****@*****.**","David Clark")
		            /// message1.BodyText.Text = "How you doing ?"
		            /// 
		            /// Dim messages As New MessageCollection
		            /// messages.Add(message)
		            /// messages.Add(message1)
		            /// 
		            /// Dim servers As New ServerCollection
		            /// servers.Add("mail.myhost.com",25)
		            /// servers.Add("mail2.myhost.com",25)
		            /// 
		            /// SmtpClient.Send(messages,servers,myErrorCollection)
		            /// 
		            /// JScript.NET
		            /// 
		            /// var message:Message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// var message1:Message = new Message();
		            /// message1.Subject = "Hey David!";
		            /// message1.From = New Address("*****@*****.**","John Doe");
		            /// message1.To.Add("*****@*****.**","David Clark");
		            /// message1.BodyText.Text = "How you doing ?";
		            /// 
		            /// var messages:MessageCollection = new MessageCollection();
		            /// messages.Add(message);
		            /// messages.Add(message1);
		            /// 
		            /// var servers:ServerCollection = new ServerCollection();
		            /// servers.Add("mail.myhost.com",25);
		            /// servers.Add("mail2.myhost.com",25);
		            /// 
		            /// SmtpClient.Send(messages,servers,myErrorCollection);
		            /// </code>
		            /// </example>
		            public static int SendCollection(MessageCollection messages, ServerCollection servers, ref SmtpExceptionCollection errors)
		            {
                        ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
			            int sent=0;
			            foreach(Message message in messages)
			            {
                            try
				            {
                                // Ensure that the mime part tree is built
                                message.CheckBuiltMimePartTree();

					            for(int i=0;i<servers.Count;i++)
					            {
						            try
                                    {
                                        if (servers[i].ServerEncryptionType != EncryptionType.None)
                                        {
#if !PocketPC
                                            smtp.ConnectSsl(servers[i].Host, servers[i].Port);
#else
                                            smtp.Connect(servers[i].Host, servers[i].Port);
#endif
                                        }
                                        else
                                        {
                                            smtp.Connect(servers[i].Host, servers[i].Port);
                                        }
							            try
							            {
								            smtp.Ehlo(System.Net.Dns.GetHostName());
							            }
							            catch
							            {
								            smtp.Helo(System.Net.Dns.GetHostName());
							            }
							            if(servers[i].Username!=null && servers[i].Username.Length>0 && servers[i].Password!=null && servers[i].Password.Length>0) smtp.Authenticate(servers[i].Username,servers[i].Password,SaslMechanism.Login);
							            if(message.From.Email!=string.Empty) smtp.MailFrom(message.From);
							            else smtp.MailFrom(message.Sender);
							            smtp.RcptTo(message.To);
							            smtp.RcptTo(message.Cc);
							            smtp.RcptTo(message.Bcc);
							            smtp.Data(message.ToMimeString());
							            smtp.Disconnect();
							            sent++;
							            break;
						            }
						            catch
						            {
							            continue;
						            }
					            }
				            }
				            catch(ActiveUp.Net.Mail.SmtpException ex) { errors.Add(ex); }
			            }
			            return sent;
		            }
Пример #28
0
 public static IAsyncResult BeginDirectSendCollection(MessageCollection messages, ServerCollection dnsServers, AsyncCallback callback)
 {
     SmtpClient._delegateDirectSendMessageCollectionServerCollection = SmtpClient.DirectSendCollection;
     return SmtpClient._delegateDirectSendMessageCollectionServerCollection.BeginInvoke(messages, dnsServers, callback, SmtpClient._delegateDirectSendMessageCollectionServerCollection);
 }
Пример #29
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(string address, ServerCollection dnsServers)
        {
            if (!ActiveUp.Net.Mail.Validator.ValidateSyntax(address)) return false;
            else
            {
                string domain = address.Split('@')[1];
                bool result;
                ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                smtp.SendTimeout = 15;
                smtp.ReceiveTimeout = 15;

                MxRecordCollection mxRecords = new MxRecordCollection();
                try
                {
#if !PocketPC
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain, dnsServers);
#else
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
#endif
                }
                catch
                {
                    new System.Exception("Can't connect to DNS server.");
                }
                smtp.Connect(mxRecords.GetPrefered().Exchange);
                try
                {
                    smtp.Ehlo(System.Net.Dns.GetHostName());
                }
                catch
                {
                    smtp.Helo(System.Net.Dns.GetHostName());
                }
                if (smtp.Verify(address)) result = true;
                else
                {
                    try
                    {
                        //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                        //smtp.MailFrom("*****@*****.**");
                        smtp.MailFrom("postmaster@" + domain);
                        smtp.RcptTo(address);
                        result = true;
                    }
                    catch
                    {
                        result = false;
                    }
                }
                smtp.Disconnect();
                return result;
            }
        }
Пример #30
0
                    /// <summary>
		            /// Sends the message using the specified host as mail exchange server.
		            /// </summary>
		            /// <param name="message">The message to be sent.</param>
		            /// <param name="servers">Servers to be used to send the message (in preference order).</param>
		            /// <example>
		            /// <code>
		            /// C#
		            /// 
		            /// Message message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// ServerCollection servers = new ServerCollection();
		            /// servers.Add("mail.myhost.com",25);
		            /// servers.Add("mail2.myhost.com",25);
		            /// 
		            /// SmtpClient.Send(message,servers);
		            /// 
		            /// VB.NET
		            /// 
		            /// Dim message As New Message
		            /// message.Subject = "Test"
		            /// message.From = New Address("*****@*****.**","John Doe")
		            /// message.To.Add("*****@*****.**","Mike Johns")
		            /// message.BodyText.Text = "Hello this is a test!"
		            /// 
		            /// Dim servers As New ServerCollection
		            /// servers.Add("mail.myhost.com",25)
		            /// servers.Add("mail2.myhost.com",25)
		            /// 
		            /// SmtpClient.Send(message,servers)
		            /// 
		            /// JScript.NET
		            /// 
		            /// var message:Message = new Message();
		            /// message.Subject = "Test";
		            /// message.From = new Address("*****@*****.**","John Doe");
		            /// message.To.Add("*****@*****.**","Mike Johns");
		            /// message.BodyText.Text = "Hello this is a test!";
		            /// 
		            /// var servers:ServerCollection = new ServerCollection();
		            /// servers.Add("mail.myhost.com",25);
		            /// servers.Add("mail2.myhost.com",25);
		            /// 
		            /// SmtpClient.Send(message,servers);
		            /// </code>
		            /// </example>
		            public static bool Send(Message message, ServerCollection servers)
		            {
			            string nothing;
			            bool sent = Send(message, servers, out nothing);
			            return sent;
		            }
Пример #31
0
 /// <summary>
 /// Sends the message using the specified DNS servers to get mail exchange servers addresses.
 /// </summary>
 /// <param name="dnsServers">Servers to be used (in preference order).</param>
 /// <example>
 /// <code>
 /// C#
 /// 
 /// SmtpMessage message = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 /// 
 /// ServerCollection servers = new ServerCollection();
 /// servers.Add("ns1.dnsserver.com",53);
 /// servers.Add("ns2.dnsserver.com",53);
 /// 
 /// message.DirectSend(servers);
 /// 
 /// VB.NET
 /// 
 /// Dim message As New SmtpMessage
 /// message.Subject = "Test"
 /// message.From = New Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.BodyText.Text = "Hello this is a test!"
 /// 
 /// Dim servers As New ServerCollection
 /// servers.Add("ns1.dnsserver.com",53)
 /// servers.Add("ns2.dnsserver.com",53)
 /// 
 /// message.DirectSend(servers)
 /// 
 /// JScript.NET
 /// 
 /// var message:SmtpMessage = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 /// 
 /// var servers:ServerCollection = new ServerCollection();
 /// servers.Add("ns1.dnsserver.com",53);
 /// servers.Add("ns2.dnsserver.com",53);
 /// 
 /// message.DirectSend(servers);
 /// </code>
 /// </example>
 public string DirectSend(ServerCollection dnsServers)
 {
     return SmtpClient.DirectSend(this, dnsServers);
 }
Пример #32
0
 public static IAsyncResult BeginSend(Message message, ServerCollection servers, out string serverMessage, AsyncCallback callback)
 {
     SmtpClient._delegateSendMessageServerCollectionString = SmtpClient.Send;
     return SmtpClient._delegateSendMessageServerCollectionString.BeginInvoke(message, servers, out serverMessage, callback, SmtpClient._delegateSendMessageServerCollectionString);
 }
Пример #33
0
 /// <summary>
 /// Validates syntax and existence of the given address.
 /// </summary>
 /// <param name="address">The address to be validated.</param>
 /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
 /// <returns>True if the address is valid, otherwise false.</returns>
 public static bool Validate(Address address, ServerCollection dnsServers)
 {
     return SmtpValidator.Validate(address.Email, dnsServers);
 }
Пример #34
0
 public static IAsyncResult BeginSendCollection(MessageCollection messages, ServerCollection servers, ref SmtpExceptionCollection errors, AsyncCallback callback)
 {
     SmtpClient._delegateSendMessageCollectionServerCollectionSmtpExceptionCollection = SmtpClient.SendCollection;
     return SmtpClient._delegateSendMessageCollectionServerCollectionSmtpExceptionCollection.BeginInvoke(messages, servers, ref errors, callback, SmtpClient._delegateSendMessageCollectionServerCollectionSmtpExceptionCollection);
 }
Пример #35
0
 /// <summary>
 /// Sends the message using the specified host as the mail exchange server.
 /// </summary>
 /// <param name="servers">Servers to be used to send the message (in preference order).</param>
 /// <example>
 /// <code>
 /// C#
 /// 
 ///SmtpMessage message = new SmtpMessage();
 ///message.From = new Address("*****@*****.**","John Doe");
 ///message.To.Add("*****@*****.**","Mike Johns");
 ///message.Subject = "hey!";
 ///message.Attachments.Add("C:\\myfile.doc");
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John.";
 ///
 ///ServerCollection servers = new ServerCollection();
 ///servers.Add("mail.myhost.com",25);
 ///servers.Add("mail2.myhost.com",25);
 ///
 ///message.Send(servers);
 /// 
 /// VB.NET
 /// 
 ///Dim message As New SmtpMessage
 ///message.From = new Address("*****@*****.**","John Doe")
 ///message.To.Add("*****@*****.**","Mike Johns")
 ///message.Subject = "hey!"
 ///message.Attachments.Add("C:\myfile.doc")
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 ///
 ///Dim servers As New ServerCollection
 ///servers.Add("mail.myhost.com",25)
 ///servers.Add("mail2.myhost.com",25)
 ///
 ///message.Send(servers)
 ///  
 /// JScript.NET
 /// 
 ///var message:SmtpMessage = new SmtpMessage();
 ///message.From = new Address("*****@*****.**","John Doe")
 ///message.To.Add("*****@*****.**","Mike Johns");
 ///message.Subject = "hey!";
 ///message.Attachments.Add("C:\\myfile.doc");
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 ///
 ///var servers:ServerCollection = new ServerCollection();
 ///servers.Add("mail.myhost.com",25);
 ///servers.Add("mail2.myhost.com",25);
 ///
 ///message.Send(servers);
 /// </code>
 /// </example>
 public void Send(ServerCollection servers)
 {
     //CheckBuiltMimePartTree();
     SmtpClient.Send(this, servers);
 }
Пример #36
0
 /// <summary>
 /// Get the MX records for the specified domain name using the system configuration.
 /// </summary>
 /// <param name="address">The domain name.</param>
 /// <param name="dnsServers">Servers to be used for MX records search.</param>
 /// <param name="timeout">The timeout in miliseconds.</param>
 /// <returns>A collection of Mx Records.</returns>
 public static ActiveUp.Net.Mail.MxRecordCollection GetMxRecords(string address, ActiveUp.Net.Mail.ServerCollection dnsServers)
 {
     return(GetMxRecords(address, dnsServers, 5000));
 }
Пример #37
0
 public static IAsyncResult BeginValidate(string address, ServerCollection servers, AsyncCallback callback)
 {
     _delegateValidateStringServers = Validate;
     return(_delegateValidateStringServers.BeginInvoke(address, servers, callback, _delegateValidateStringServers));
 }
Пример #38
0
 public Boolean AddHost(string host)
 {
     try
     {
         if (Session["Hosts"] != null && Session["Hosts"] as ServerCollection != null)
         {
             ((ServerCollection)Session["Hosts"]).Add(host);
         }
         else
         {
             Session["Hosts"] = new ServerCollection();
             ((ServerCollection)Session["Hosts"]).Add(host);
         }
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Пример #39
0
 /// <summary>
 /// Validates syntax and existence of the given address.
 /// </summary>
 /// <param name="address">The address to be validated.</param>
 /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
 /// <returns>True if the address is valid, otherwise false.</returns>
 public static bool Validate(Address address, ServerCollection dnsServers)
 {
     return(Validate(address.Email, dnsServers));
 }
Пример #40
0
 /// <summary>
 /// Sends the message using the specified host as dns server on the specified port.
 /// </summary>
 /// <param name="host">The host to be used.</param>
 /// <param name="port">The port to be used.</param>
 /// <example>
 /// <code>
 /// C#
 /// 
 /// SmtpMessage message = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 /// 
 /// message.DirectSend("ns1.dnsserver.com",53);
 /// 
 /// VB.NET
 /// 
 /// Dim message As New SmtpMessage
 /// message.Subject = "Test"
 /// message.From = New Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.BodyText.Text = "Hello this is a test!"
 /// 
 /// message.DirectSend("ns1.dnsserver.com",53)
 /// 
 /// JScript.NET
 /// 
 /// var message:SmtpMessage = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 /// 
 /// message.DirectSend("ns1.dnsserver.com",53);
 /// </code>
 /// </example>
 public string DirectSend(string dnsHost, int dnsPort)
 {
     ActiveUp.Net.Mail.ServerCollection servers = new ActiveUp.Net.Mail.ServerCollection();
     servers.Add(dnsHost, dnsPort);
     return DirectSend(servers);
 }
Пример #41
0
 public static IAsyncResult BeginValidate(Address address, ServerCollection dnsServers, AsyncCallback callback)
 {
     _delegateValidateAddressServers = Validate;
     return(_delegateValidateAddressServers.BeginInvoke(address, dnsServers, callback, _delegateValidateAddressServers));
 }
Пример #42
0
 public IAsyncResult BeginDirectSend(ServerCollection dnsServers, AsyncCallback callback)
 {
     return SmtpClient.BeginDirectSend(this, dnsServers, callback);
 }
Пример #43
0
 /// <summary>
 /// Get the MX records for the specified domain name using the system configuration.
 /// </summary>
 /// <param name="address">The domain name.</param>
 /// <param name="dnsServers">Servers to be used for MX records search.</param>
 /// <param name="timeout">The timeout in miliseconds.</param>
 /// <returns>A collection of Mx Records.</returns>
 public static MxRecordCollection GetMxRecords(string address, ServerCollection dnsServers)
 {
     return(GetMxRecords(address, dnsServers, 5000));
 }