Exemple #1
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;
		            }
Exemple #2
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;
                    }
Exemple #3
0
 /// <summary>
 /// Appends the provided message to the mailbox.
 /// </summary>
 /// <param name="message">The message to be appended.</param>
 /// <param name="flags">Flags to be set for the message.</param>
 /// <param name="dateTime">The internal date to be set for the message.</param>
 /// <example>
 /// <code>
 /// C#
 ///  
 /// Message message = new Message();
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.Subject = "hey!";
 /// message.Attachments.Add("C:\\myfile.doc");
 /// message.HtmlBody.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John.";
 /// 
 /// FlagCollection flags = new FlagCollection();
 /// flags.Add("Read");
 /// 
 /// Imap4Client imap = new Imap4Client();
 /// Mailbox inbox = imap.SelectMailbox("Read Messages");
 /// inbox.Append(message,flags,System.DateTime.Now);
 /// imap.Disconnect();
 ///  
 /// VB.NET
 ///  
 /// Dim message As New Message
 /// message.From = new Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.Subject = "hey!"
 /// message.Attachments.Add("C:\myfile.doc")
 /// message.HtmlBody.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 /// 
 /// Dim flags As New FlagCollection
 /// flags.Add("Read")
 ///  
 /// Dim imap As New Imap4Client
 /// Dim inbox As Mailbox = imap.SelectMailbox("Read Messages")
 /// inbox.Append(message,flags,System.DateTime.Now)
 /// imap.Disconnect()
 ///   
 /// JScript.NET
 ///  
 /// var message:Message = new Message();
 /// message.From = new Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.Subject = "hey!";
 /// message.Attachments.Add("C:\\myfile.doc");
 /// message.HtmlBody.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 /// 
 /// var flags:FlagCollection = new FlagCollection();
 /// flags.Add("Read");
 ///  
 /// var imap:Imap4Client = new Imap4Client();
 /// var inbox:Mailbox = imap.SelectMailbox("Read Messages");
 /// inbox.Append(message,flags,System.DateTime.Now);
 /// imap.Disconnect();
 /// </code>
 /// </example>
 public string Append(Message message, IFlagCollection flags, DateTime dateTime)
 {
     return this.Append(message.ToMimeString(),flags,dateTime);
 }
Exemple #4
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;
                    }
        public Message ToMimeMessage(int tenant, string user, bool loadAttachments)
        {
            var mimeMessage = new Message
                {
                    Date = DateTime.UtcNow,
                    From = new Address(From, string.IsNullOrEmpty(DisplayName) ? "" : Codec.RFC2047Encode(DisplayName))
                };

            if (Important)
                mimeMessage.Priority = MessagePriority.High;

            mimeMessage.To.AddRange(To.ConvertAll(address =>
                {
                    var addr = Parser.ParseAddress(address);
                    addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                    return new Address(addr.Email, addr.Name);
                }));

            mimeMessage.Cc.AddRange(Cc.ConvertAll(address =>
                {
                    var addr = Parser.ParseAddress(address);
                    addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                    return new Address(addr.Email, addr.Name);
                }));

            mimeMessage.Bcc.AddRange(Bcc.ConvertAll(address =>
                {
                    var addr = Parser.ParseAddress(address);
                    addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                    return new Address(addr.Email, addr.Name);
                }));

            mimeMessage.Subject = Codec.RFC2047Encode(Subject);

            // Set correct body
            if (Attachments.Any() || AttachmentsEmbedded.Any())
            {
                foreach (var attachment in Attachments)
                {
                    attachment.user = user;
                    attachment.tenant = tenant;
                    var attach = CreateAttachment(attachment, loadAttachments);
                    if (attach != null)
                        mimeMessage.Attachments.Add(attach);
                }

                foreach (var embeddedAttachment in AttachmentsEmbedded)
                {
                    embeddedAttachment.user = user;
                    embeddedAttachment.tenant = tenant;
                    var attach = CreateAttachment(embeddedAttachment, true);
                    if (attach != null)
                        mimeMessage.EmbeddedObjects.Add(attach);
                }
            }

            mimeMessage.MessageId = MimeMessageId;
            mimeMessage.InReplyTo = MimeReplyToId;

            mimeMessage.BodyText.Charset = Encoding.UTF8.HeaderName;
            mimeMessage.BodyText.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            mimeMessage.BodyText.Text = "";

            mimeMessage.BodyHtml.Charset = Encoding.UTF8.HeaderName;
            mimeMessage.BodyHtml.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            mimeMessage.BodyHtml.Text = HtmlBody;

            mimeMessage.OriginalData = Encoding.GetEncoding("iso-8859-1").GetBytes(mimeMessage.ToMimeString());

            return mimeMessage;
        }
Exemple #6
0
 /// <summary>
 /// Appends the provided message to the mailbox.
 /// </summary>
 /// <param name="message">The message to be appended.</param>
 /// <example>
 /// <code>
 /// C#
 ///  
 /// Message message = new Message();
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.Subject = "hey!";
 /// message.Attachments.Add("C:\\myfile.doc");
 /// message.HtmlBody.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John.";
 /// 
 /// Imap4Client imap = new Imap4Client();
 /// Mailbox inbox = imap.SelectMailbox("inbox");
 /// inbox.Append(message);
 /// imap.Disconnect();
 ///  
 /// VB.NET
 ///  
 /// Dim message As New Message
 /// message.From = new Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.Subject = "hey!"
 /// message.Attachments.Add("C:\myfile.doc")
 /// message.HtmlBody.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 /// 
 /// Dim imap As New Imap4Client
 /// Dim inbox As Mailbox = imap.SelectMailbox("inbox")
 /// inbox.Append(message)
 /// imap.Disconnect()
 ///   
 /// JScript.NET
 ///  
 /// var message:Message = new Message();
 /// message.From = new Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.Subject = "hey!";
 /// message.Attachments.Add("C:\\myfile.doc");
 /// message.HtmlBody.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 /// 
 /// var imap:Imap4Client = new Imap4Client();
 /// var inbox:Mailbox = imap.SelectMailbox("inbox");
 /// inbox.Append(message);
 /// imap.Disconnect();
 /// </code>
 /// </example>
 public string Append(Message message)
 {
     return this.Append(message.ToMimeString());
 }
Exemple #7
0
 private void SendMessageWithAuthentication(string username, string password,
                                                   SaslMechanism mechanism, Message message)
 {
     Authenticate(username, password, mechanism);
     if (message.From.Email != string.Empty) MailFrom(message.From);
     else MailFrom(message.Sender);
     RcptTo(message.To);
     RcptTo(message.Cc);
     RcptTo(message.Bcc);
     Data(message.ToMimeString());
     Disconnect();
 }
 private static void SendMessageWithAuthentication(SmtpClient smtp, string username, string password,
                                                   SaslMechanism mechanism, Message message)
 {
     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();
 }
Exemple #9
0
 private void SendMessageWith(Message message)
 {
     if (message.From.Email != string.Empty) MailFrom(message.From);
     else MailFrom(message.Sender);
     RcptTo(message.To);
     RcptTo(message.Cc);
     RcptTo(message.Bcc);
     Data(message.ToMimeString()); //,(message.Charset!=null ? message.Charset : "iso-8859-1"));
     Disconnect();
 }
Exemple #10
0
        /// <summary>
        /// Sends the message using the specified host as mail exchange server on the specified port.
        /// </summary>
        /// <param name="message">The message to be sent.</param>
        /// <param name="host">The host to be used.</param>
        /// <param name="port">The port to be used.</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!";
        /// 
        /// SmtpClient.Send(message,"mail.myhost.com",8504);
        /// 
        /// 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!"
        /// 
        /// SmtpClient.Send(message,"mail.myhost.com",8504)
        /// 
        /// 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!";
        /// 
        /// SmtpClient.Send(message,"mail.myhost.com",8504);
        /// </code>
        /// </example>
        public bool Send(Message message, string host, int port)
        {
            // Ensure that the mime part tree is built
            message.CheckBuiltMimePartTree();

            ConnectPlain(host, port);
            try
            {
                Ehlo(System.Net.Dns.GetHostName());
            }
            catch
            {
                Helo(System.Net.Dns.GetHostName());
            }
            if (message.From.Email != string.Empty) MailFrom(message.From);
            else MailFrom(message.Sender);
            RcptTo(message.To);
            RcptTo(message.Cc);
            RcptTo(message.Bcc);
            Data(message.ToMimeString());
            Disconnect();
            return true;
        }
 public void Send(object sender, System.EventArgs e)
 {
     ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();
     try
     {
         message.Subject = iSubject.Text;
         message.To = ActiveUp.Net.Mail.Parser.ParseAddresses(iTo.Text);
         message.Cc = ActiveUp.Net.Mail.Parser.ParseAddresses(iCc.Text);
         message.Bcc = ActiveUp.Net.Mail.Parser.ParseAddresses(iBcc.Text);
         if (iReplyTo.Text.Length > 0)
             message.ReplyTo = ActiveUp.Net.Mail.Parser.ParseAddresses(iReplyTo.Text)[0];
         string s1 = iBody.Text;
         string[] sArr1 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
         for (int i1 = 0; i1 < sArr1.Length; i1++)
         {
             string s2 = sArr1[i1];
             if ((s2.IndexOf(Session.SessionID + "_Image_\uFFFD") != -1) && (s1.IndexOf(s2.Substring(s2.IndexOf(Session.SessionID))) != -1))
             {
                 ActiveUp.Net.Mail.MimePart embeddedObject1 = new ActiveUp.Net.Mail.MimePart(s2, true, string.Empty);
                 embeddedObject1.ContentName = s2.Substring(s2.IndexOf("_Image_\uFFFD") + 7);
                 message.EmbeddedObjects.Add(embeddedObject1);
                 s1 = s1.Replace("http://\uFFFD" + Request.ServerVariables["HTTP_HOST\uFFFD"] + Request.ServerVariables["URL\uFFFD"].Substring(0, Request.ServerVariables["URL\uFFFD"].LastIndexOf("/\uFFFD") + 1) + "temp\uFFFD" + s2.Substring(s2.LastIndexOf('\\')).Replace("\\\uFFFD", "/\uFFFD"), "cid:\uFFFD" + embeddedObject1.ContentId);
                 s1 = s1.Replace("temp\uFFFD" + s2.Substring(s2.LastIndexOf('\\')).Replace("\\\uFFFD", "/\uFFFD"), "cid:\uFFFD" + embeddedObject1.ContentId);
             }
         }
         string[] sArr3 = System.IO.Directory.GetFiles(Server.MapPath("icons/emoticons/\uFFFD"));
         for (int i2 = 0; i2 < sArr3.Length; i2++)
         {
             string s3 = sArr3[i2];
             if (s1.IndexOf("icons/emoticons\uFFFD" + s3.Substring(s3.LastIndexOf("\\\uFFFD")).Replace("\\\uFFFD", "/\uFFFD")) != -1)
             {
                 ActiveUp.Net.Mail.MimePart embeddedObject2 = new ActiveUp.Net.Mail.MimePart(s3, true, string.Empty);
                 embeddedObject2.ContentName = s3.Substring(s3.LastIndexOf("\\\uFFFD") + 1);
                 message.EmbeddedObjects.Add(embeddedObject2);
                 s1 = s1.Replace("http://\uFFFD" + Request.ServerVariables["HTTP_HOST\uFFFD"] + Request.ServerVariables["URL\uFFFD"].Substring(0, Request.ServerVariables["URL\uFFFD"].LastIndexOf("/\uFFFD") + 1) + "icons/emoticons\uFFFD" + s3.Substring(s3.LastIndexOf('\\')).Replace("\\\uFFFD", "/\uFFFD"), "cid:\uFFFD" + embeddedObject2.ContentId);
             }
         }
         message.BodyHtml.Text = s1;
         message.BodyText.Text = iBody.TextStripped;
         //message.Headers.Add("x-sender-ip\uFFFD", Request.ServerVariables["REMOTE_ADDR\uFFFD"]);
         string[] sArr5 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
         for (int i3 = 0; i3 < sArr5.Length; i3++)
         {
             string s4 = sArr5[i3];
             if (s4.IndexOf("\\temp\\\uFFFD" + Session.SessionID + "_Attach_\uFFFD") != -1)
             {
                 ActiveUp.Net.Mail.MimePart attachment = new ActiveUp.Net.Mail.MimePart(s4, true);
                 attachment.Filename = s4.Substring(s4.IndexOf("_Attach_\uFFFD") + 8);
                 attachment.ContentName = s4.Substring(s4.IndexOf("_Attach_\uFFFD") + 8);
                 message.Attachments.Add(attachment);
             }
         }
         message.From = new ActiveUp.Net.Mail.Address(iFromEmail.Text, iFromName.Text);
         if (((System.Web.UI.HtmlControls.HtmlInputButton)sender).ID == "iSubmit\uFFFD")
         {
             try
             {
                 message.Send((string)Application["smtpserver\uFFFD"], System.Convert.ToInt32(Application["smtpport\uFFFD"]), (string)Application["user\uFFFD"], (string)Application["password\uFFFD"], ActiveUp.Net.Mail.SaslMechanism.CramMd5);
             }
             catch
             {
                 try
                 {
                     message.Send((string)Application["smtpserver\uFFFD"], System.Convert.ToInt32(Application["smtpport\uFFFD"]), (string)Application["user\uFFFD"], (string)Application["password\uFFFD"], ActiveUp.Net.Mail.SaslMechanism.CramMd5);
                 }
                 catch
                 {
                     message.Send((string)Application["smtpserver\uFFFD"], System.Convert.ToInt32(Application["smtpport\uFFFD"]));
                 }
             }
             try
             {
                 if (iAction.Value == "r\uFFFD")
                 {
                     ActiveUp.Net.Mail.Mailbox mailbox1 = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(MailboxName);
                     ActiveUp.Net.Mail.FlagCollection flagCollection = new ActiveUp.Net.Mail.FlagCollection();
                     flagCollection.Add("Answered\uFFFD");
                     if (mailbox1.Fetch.Flags(MessageId).Merged.ToLower().IndexOf("\\answered\uFFFD") == -1)
                         mailbox1.AddFlagsSilent(MessageId, flagCollection);
                 }
                 lConfirm.Text = ((Language)Session["language\uFFFD"]).Words[32].ToString() + " : <br /><br />\uFFFD" + message.To.Merged + message.Cc.Merged + message.Bcc.Merged.Replace(";\uFFFD", "<br />\uFFFD");
                 pForm.Visible = false;
                 pConfirm.Visible = true;
                 System.Web.HttpCookie httpCookie1 = new System.Web.HttpCookie("fromname\uFFFD", iFromName.Text);
                 System.Web.HttpCookie httpCookie2 = new System.Web.HttpCookie("fromemail\uFFFD", iFromEmail.Text);
                 System.Web.HttpCookie httpCookie3 = new System.Web.HttpCookie("replyto\uFFFD", iReplyTo.Text);
                 System.DateTime dateTime1 = System.DateTime.Now;
                 httpCookie1.Expires = dateTime1.AddMonths(2);
                 System.DateTime dateTime2 = System.DateTime.Now;
                 httpCookie2.Expires = dateTime2.AddMonths(2);
                 System.DateTime dateTime3 = System.DateTime.Now;
                 httpCookie3.Expires = dateTime3.AddMonths(2);
                 Response.Cookies.Add(httpCookie1);
                 Response.Cookies.Add(httpCookie2);
                 Response.Cookies.Add(httpCookie3);
                 if (cSave.Checked)
                 {
                     System.Web.HttpCookie httpCookie4 = new System.Web.HttpCookie("folder\uFFFD", dBoxes.SelectedItem.Text);
                     System.DateTime dateTime4 = System.DateTime.Now;
                     httpCookie4.Expires = dateTime4.AddMonths(2);
                     Response.Cookies.Add(httpCookie4);
                     ActiveUp.Net.Mail.Mailbox mailbox2 = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(dBoxes.SelectedItem.Text);
                     mailbox2.Append(message.ToMimeString());
                 }
                 string[] sArr6 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
                 for (int i4 = 0; i4 < sArr6.Length; i4++)
                 {
                     string s5 = sArr6[i4];
                     if (s5.IndexOf(Session.SessionID) != -1)
                         System.IO.File.Delete(s5);
                 }
             }
             catch (System.Exception e1)
             {
                 Page.RegisterStartupScript("ShowError\uFFFD", "<script>ShowErrorDialog('\uFFFD" + ((Language)Session["language\uFFFD"]).Words[83].ToString() + "','\uFFFD" + System.Text.RegularExpressions.Regex.Escape(e1.Message + e1.StackTrace).Replace("'\uFFFD", "\\'\uFFFD") + "');</script>\uFFFD");
             }
         }
         else
         {
             System.Web.HttpCookie httpCookie5 = new System.Web.HttpCookie("folder\uFFFD", dBoxes.SelectedItem.Text);
             System.DateTime dateTime5 = System.DateTime.Now;
             httpCookie5.Expires = dateTime5.AddMonths(2);
             Response.Cookies.Add(httpCookie5);
             ActiveUp.Net.Mail.Mailbox mailbox3 = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(dBoxes.SelectedItem.Text);
             mailbox3.Append(message.ToMimeString());
         }
         string[] sArr8 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
         for (int i5 = 0; i5 < sArr8.Length; i5++)
         {
             string s6 = sArr8[i5];
             if (s6.IndexOf(Session.SessionID) != -1)
                 System.IO.File.Delete(s6);
         }
     }
     catch (System.Exception e2)
     {
         Page.RegisterStartupScript("ShowError\uFFFD", "<script>ShowErrorDialog('\uFFFD" + ((Language)Session["language\uFFFD"]).Words[82].ToString() + "','\uFFFD" + System.Text.RegularExpressions.Regex.Escape(e2.Message + e2.StackTrace).Replace("'\uFFFD", "\\'\uFFFD") + "');</script>\uFFFD");
     }
 }
Exemple #12
0
        /// <summary>
        /// Queries the server.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        /// <param name="message">The message.</param>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        private static CtchResponse QueryServer(string host, int port, Message message, string filename)
        {
            bool reference = true;

            if (message != null)
                reference = false;
            else
                message = Parser.ParseMessageFromFile(filename);
            
            string version = "0000001";
            
            // Prepare the commtouch headers
            string content = string.Format("X-CTCH-PVer: {0}\r\nX-CTCH-MailFrom: {1}\r\nX-CTCH-SenderIP: {2}\r\n", version, message.Sender.Email, message.SenderIP);

            if (reference)
            {
                content += string.Format("X-CTCH-FileName: {0}\r\n", filename);
            }
            else
            {
                content += string.Format("\r\n{0}", message.ToMimeString());
            }

            // Prepare the request with HTTP header
            string request = string.Format("POST /ctasd/{0} HTTP/1.0\r\nContent-Length: {1}\r\n\r\n", (reference ? "ClassifyMessage_File" : "ClassifyMessage_Inline"), content.Length)
                + content;

            //try
            //{

                TcpClient client = new TcpClient();
                client.Connect(host, port);

                Byte[] data = System.Text.Encoding.ASCII.GetBytes(request);

                //  Stream stream = client.GetStream();
                NetworkStream stream = client.GetStream();

                // Send the message to the connected TcpServer. 
                stream.Write(data, 0, data.Length);

#if DEBUG
                Console.WriteLine("<requestSent>");
                Console.WriteLine("{0}", request);
                Console.WriteLine("</requestSent>");
#endif
                // Receive the TcpServer.response.

                // Buffer to store the response bytes.
                data = new Byte[256];

                // String to store the response ASCII representation.
                String responseData = String.Empty;

                // Read the first batch of the TcpServer response bytes.
                Int32 bytes = stream.Read(data, 0, data.Length);
                responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

#if DEBUG
                Console.WriteLine("<responseReceived>");
                Console.WriteLine("{0}", responseData);
                Console.WriteLine("</responseReceived>");
#endif

                CtchResponse ctchResponse = CtchResponse.ParseFromString(responseData);

#if DEBUG
                Console.WriteLine(ctchResponse.ToString());
#endif
                // Close everything.
                stream.Close();
                client.Close();
            //}
            //catch (ArgumentNullException e)
            //{
            //    Console.WriteLine("ArgumentNullException: {0}", e);
            //}
            //catch (SocketException e)
            //{
            //    Console.WriteLine("SocketException: {0}", e);
            //}

            return ctchResponse;
        }
                    /// <summary>
                    /// Sends the message using the specified host on the specified port. Secure SASL Authentication is performed according to the requested mechanism.
                    /// </summary>
                    /// <param name="message">The message to be sent.</param>
                    /// <param name="host">The host to be used.</param>
                    /// <param name="username">The username to be used for authentication.</param>
                    /// <param name="password">The password to be used for authentication.</param>
                    /// <param name="mechanism">SASL Mechanism to be used for authentication.</param>
                    /// <param name="port">The port to be used.</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!";
                    /// 
                    /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
                    /// 
                    /// 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!"
                    /// 
                    /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504)
                    /// 
                    /// 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!";
                    /// 
                    /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
                    /// </code>
                    /// </example>
                    public static bool Send(Message message, string host, int port, string username, string password, SaslMechanism mechanism)
                    {
                        // Ensure that the mime part tree is built
                        message.CheckBuiltMimePartTree();

                        var smtp = new SmtpClient();
                        smtp.Connect(host,port);
                        smtp.SendEhloHelo();
                        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;
                    }
Exemple #14
0
		            /// <summary>
		            /// Sends the message using the specified host on the specified port. Secure SASL Authentication is performed according to the requested mechanism.
		            /// </summary>
		            /// <param name="message">The message to be sent.</param>
		            /// <param name="host">The host to be used.</param>
		            /// <param name="username">The username to be used for authentication.</param>
		            /// <param name="password">The password to be used for authentication.</param>
		            /// <param name="mechanism">SASL Mechanism to be used for authentication.</param>
		            /// <param name="port">The port to be used.</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!";
		            /// 
		            /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
		            /// 
		            /// 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!"
		            /// 
		            /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504)
		            /// 
		            /// 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!";
		            /// 
		            /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
		            /// </code>
		            /// </example>
		            public static bool Send(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.Connect(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;
		            }
Exemple #15
0
        /// <summary>
        /// Sends the message using the specified host on the specified port. Secure SASL Authentication is performed according to the requested mechanism.
        /// </summary>
        /// <param name="message">The message to be sent.</param>
        /// <param name="host">The host to be used.</param>
        /// <param name="username">The username to be used for authentication.</param>
        /// <param name="password">The password to be used for authentication.</param>
        /// <param name="mechanism">SASL Mechanism to be used for authentication.</param>
        /// <param name="port">The port to be used.</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!";
        /// 
        /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
        /// 
        /// 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!"
        /// 
        /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504)
        /// 
        /// 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!";
        /// 
        /// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
        /// </code>
        /// </example>
        public bool Send(Message message, string host, int port, string username, string password,
                                SaslMechanism mechanism)
        {
            // Ensure that the mime part tree is built
            message.CheckBuiltMimePartTree();

            ConnectPlain(host, port);
            SendEhloHelo();
            Authenticate(username, password, mechanism);
            if (message.From.Email != string.Empty) MailFrom(message.From);
            else MailFrom(message.Sender);
            RcptTo(message.To);
            RcptTo(message.Cc);
            RcptTo(message.Bcc);
            Data(message.ToMimeString());
            Disconnect();
            return true;
        }
Exemple #16
0
		/// <summary>
		/// Posts the provided article.
		/// </summary>
		/// <param name="article">The article data as a string.</param>
		/// <returns>The server's response.</returns>
		/// <example>
		/// <code>
		/// C#
		/// 
		/// Message article = new Message();
		/// article.HeaderFields.Add("NewsGroups","myhost.info");
		/// article.From = new Address("*****@*****.**","John Doe");
		/// article.Subject = "Test";
		/// article.Body = "Hello this is a test !";
		/// NntpClient nttp = new NntpClient();
		/// nntp.Connect("news.myhost.com");
		/// if(nntp.PostingAllowed) nntp.Post(article);
		/// else throw new NntpException("Posting not allowed. Couldn't post.");
		/// nntp.Disconnect();
		/// 
		/// VB.NET
		/// 
		/// Dim article as New Message
		/// article.HeaderFields.Add("NewsGroups","myhost.info")
		/// article.From = New Address("*****@*****.**","John Doe")
		/// article.Subject = "Test"
		/// article.Body = "Hello this is a test !"
		/// Dim nttp as New NntpClient()
		/// nntp.Connect("news.myhost.com") 
		/// If nntp.PostingAllowed Then
		/// nntp.Post(article)
		/// Else
		/// Throw New NntpException("Posting not allowed. Couldn't post.")
		/// End If
		/// nntp.Disconnect()
		/// 
		/// JScript.NET
		/// 
		/// var article:Message = new Message();
		/// article.HeaderFields.Add("NewsGroups","myhost.info");
		/// article.From = new Address("*****@*****.**","John Doe");
		/// article.Subject = "Test";
		/// article.Body = "Hello this is a test !";
		/// var nntp:NntpClient = new NntpClient();
		/// nntp.Connect("news.myhost.com");
		/// if(nntp.PostingAllowed) nntp.Post(article);
		/// else throw new NntpException("Posting not allowed. Couldn't post.");
		/// nntp.Disconnect();
		/// </code>
		/// </example>
		public string Post(Message article)
		{
			return this.Post(article.ToMimeString());
		}
 private static void SendMessageWith(SmtpClient smtp, Message message)
 {
     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();
 }