Exemplo n.º 1
0
                    public static bool SendSsl(Message message, string host, int port, string username, string password, SaslMechanism mechanism)
                    {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

                        ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                        smtp.ConnectSsl(host, port);
                        try
                        {
                            smtp.Ehlo(System.Net.Dns.GetHostName());
                        }
                        catch
                        {
                            smtp.Helo(System.Net.Dns.GetHostName());
                        }
                        smtp.Authenticate(username, password, mechanism);
                        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();
                        return true;
                    }
Exemplo n.º 2
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;
		            }
Exemplo n.º 3
0
                    public static bool SendSsl(Message message, string server, int port)
                    {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

                        ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                        smtp.ConnectSsl(server, port);
                        try
                        {
                            smtp.Ehlo(System.Net.Dns.GetHostName());
                        }
                        catch
                        {
                            smtp.Helo(System.Net.Dns.GetHostName());
                        }
                        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());//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
                        smtp.Disconnect();
                        return true;
                    }
Exemplo n.º 4
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;
		            }
Exemplo n.º 5
0
                    public static bool SendSsl(Message message, string host, int port, string username, string password, SaslMechanism mechanism, EncryptionType enc_type)
                    {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

                        ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                        switch (enc_type)
                        {
                            case EncryptionType.SSL:
                                smtp.ConnectSsl(host, port);
                                break;
                            case EncryptionType.StartTLS:
                                smtp.Connect(host, port);
                                break;
                            default:
                                throw new ArgumentException("Incompatible EncriptionType with SendSSL: " + enc_type);
                        }

                        smtp.SendEhloHelo();

                        if (enc_type == EncryptionType.StartTLS)
                        {
                            smtp.StartTLS(host);
                        }

                        SendMessageWithAuthentication(smtp, username, password, mechanism, message);
                        return true;
                    }
Exemplo n.º 6
0
                    public static bool SendSsl(Message message, string host, int port, string username, string password, SaslMechanism mechanism)
                    {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

                        ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                        smtp.ConnectSsl(host, port);
                        smtp.SendEhloHelo();
                        SendMessageWithAuthentication(smtp, username, password, mechanism, message);
                        return true;
                    }
Exemplo n.º 7
0
                    public static bool SendSsl(Message message, string server, int port)
                    {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

                        ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                        smtp.ConnectSsl(server, port);
                        smtp.SendEhloHelo();
                        SendMessageWith(smtp, message);
                        return true;
                    }