private void sendTestMessageButton_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Sending test message using DirectSend()");

            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();
            message.From.Email = this.emailAddressTextbox.Text;
            message.To.Add(this.emailAddressTextbox.Text);
            message.Subject = "This is a notification test.";
            message.BodyText.Text = "This is a notification test.";
            message.DirectSend();

            this.AddLogEntry("Notification test message sent.");
        }
Esempio n. 2
1
        private void messagesExplorerListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.messageRfc822RawTextbox.Text = this.messagesExplorerListBox.SelectedItem.ToString();

            ActiveUp.Net.Mail.Message message = ActiveUp.Net.Mail.Parser.ParseMessage(this.messageRfc822RawTextbox.Text);
            this.messageDetailObjectExplorer.SelectedObject = message;
            _selectedMessage = message;
            this.dataGridView1.DataSource = message.Attachments;
        }
        public void PrepareMessageForSerialization()
        {
            var test_mail = new Message
            {
                From = { Email = "*****@*****.**", Name = Codec.RFC2047Encode("test") },
                To = { new Address { Email = "*****@*****.**", Name = Codec.RFC2047Encode("name1") },
                       new Address { Email = "*****@*****.**", Name = Codec.RFC2047Encode("name2") } },
                Subject = Codec.RFC2047Encode("test"),
                BodyText = { Charset = utf8_charset,
                            ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable,
                            Text = "test" },
                BodyHtml = { Charset = utf8_charset,
                             ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable,
                             Text = "<a href='www.teamlab.com'>test</a>" }
            };

            test_mail.StoreToFile(TestFilePath);
        }
        public static void TestPrepareMessage()
        {
            var charset = Encoding.UTF8.HeaderName;
            const string text = "тест";
            const string html = "<a href='www.teamlab.com'>" + text + "</a>";

            var message = new Message
                {
                    From = {Email = "*****@*****.**", Name = Codec.RFC2047Encode(text)}
                };

            message.To.Add("*****@*****.**", Codec.RFC2047Encode(text));

            message.Subject = Codec.RFC2047Encode(text);

            message.BodyText.Charset = charset;
            message.BodyText.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            message.BodyText.Text = text;
            message.BodyHtml.Charset = charset;
            message.BodyHtml.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            message.BodyHtml.Text = html;

            message.StoreToFile(@"test_send_prepared.eml");
        }
Esempio n. 5
0
        /// <summary>
        /// Create the message body ".eml" file.
        /// </summary>
        /// <param name="mailMessage">The mail message object.</param>
        /// <param name="message">ActiveUp.Net.Mail.Message message</param>
        /// <param name="mailbox">The mailbox.</param>
        public void CreateMessageBodyFile(MailMessage mailMessage, ActiveUp.Net.Mail.Message message,
                                          string mailbox)
        {
            // verify if the messages directory exist, if not create it.
            string directory = Constants.Messages;

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            // create the file with the message.
            string fileName = string.Concat(mailMessage.Id, ".eml");
            string path     = System.IO.Path.Combine(directory, fileName);

            if (!File.Exists(path))
            {
                if (message == null)
                {
                    message = this.GetMessage(mailMessage, mailbox);
                }

                if (message != null)
                {
                    FileStream   fileStream = File.Create(path);
                    StreamWriter sw         = new StreamWriter(fileStream);
                    sw.Write(message.BodyText.Text);
                    sw.Close();
                }
            }

            mailMessage.Path = path;
        }
Esempio n. 6
0
        private void UpdateMailFromBox(string box, DateTime lastSyncDate)
        {
            Mailbox inbox   = _imap4Client.SelectMailbox(box);
            string  strDate = lastSyncDate.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture);

            ActiveUp.Net.Mail.Message mail = null;
            int[] ids = inbox.Search("SENTSINCE " + strDate);
            if (ids.Length > 0)
            {
                TimeFilter timeFilter = new TimeFilter();
                timeFilter.SetRule(lastSyncDate);
                this.AppendFilter(timeFilter);
                for (int l = ids.Length - 1; l >= 0; l--)
                {
                    mail = inbox.Fetch.MessageObject(ids[l]);
                    if (IsCorrectMail(mail))
                    {
                        EmailDetail email = new EmailDetail(ids[l], ConvertUniversalTime(mail), mail.Subject, mail.From.Email, box);
                        email.AttachNames.AddRange(GetAttachmentFileNameFromMail(_savePath, mail));
                        emailDetailList.Add(email);
                        GetAttachmentFromMail(_savePath, mail);
                    }
                }
            }
        }
Esempio n. 7
0
 public void Update(MailUser user, ActiveUp.Net.Mail.Message entity)
 {
     using (IMailMessageDao dao = getDaoContext().DaoImpl.MailMessageDao)
     {
         dao.Update(user, entity);
     }
 }
Esempio n. 8
0
 public void Insert(ActiveUp.Net.Mail.DeltaExt.MailUser us, ActiveUp.Net.Mail.Message mex)
 {
     using (IMailMessageDao dao = getDaoContext().DaoImpl.MailMessageDao)
     {
         dao.Insert(us, mex);
     }
 }
Esempio n. 9
0
 public void Insert(ActiveUp.Net.Mail.Message entity)
 {
     using (IMailMessageDao dao = getDaoContext().DaoImpl.MailMessageDao)
     {
         dao.Insert(entity);
     }
 }
Esempio n. 10
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Start work");

            string sHostPop  = "pop.googlemail.com";
            string sHostImap = "imap.googlemail.com";
            int    nPort     = 995;
            string sUserName = "******";
            string sPasword  = "theSimpsons";

            try
            {
                string sEml = @"E:\ut8_encripted_teamlab.eml";

                ActiveUp.Net.Mail.Message m =
                    ActiveUp.Net.Mail.Parser.ParseMessageFromFile(sEml);
                var header = ActiveUp.Net.Mail.Parser.ParseHeader(sEml);

                Pop3Client pop = new Pop3Client();

                // Connect to the pop3 client
                pop.ConnectSsl(sHostPop, nPort, "recent:" + sUserName, sPasword);

                if (pop.MessageCount > 0)
                {
                    ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(4);
                    string sHtml = message.BodyHtml.Text;
                }
                else
                {
                    System.Console.WriteLine("No letters!");
                }

                pop.Disconnect();

                Imap4Client imap = new Imap4Client();

                imap.ConnectSsl(sHostImap, 993);

                imap.Login(sUserName, sPasword, "");

                Mailbox inbox = imap.SelectMailbox("inbox");

                if (inbox.MessageCount > 0)
                {
                    ActiveUp.Net.Mail.Message message = inbox.Fetch.MessageObject(6);
                    string sHtml = message.BodyHtml.Text;
                }

                imap.Disconnect();
            }
            catch (Exception ex)
            {
                System.Console.Write("\r\n" + ex);
            }

            System.Console.WriteLine("Stop work");

            System.Console.ReadKey();
        }
        protected void CreateRightResult(Message eml_message, string out_file_path)
        {
            var result = new RightParserResult();
            result.From = new TestAddress();

            result.From.Email = eml_message.From.Email;
            result.From.Name = eml_message.From.Name;

            result.To = new List<TestAddress>();
            foreach (var to_adresses in eml_message.To)
            {
                result.To.Add(new TestAddress {Name = to_adresses.Name, Email = to_adresses.Email});
            }

            result.Cc = new List<TestAddress>();
            foreach (var cc_adresses in eml_message.Cc)
            {
                result.Cc.Add(new TestAddress {Name = cc_adresses.Name, Email = cc_adresses.Email});
            }

            result.Subject = eml_message.Subject;
            result.AttachmentCount = eml_message.Attachments.Count;
            result.UnknownPatsCount = eml_message.UnknownDispositionMimeParts.Count;

            result.HtmlBody = eml_message.BodyHtml.Text;
            result.HtmlCharset = eml_message.BodyHtml.Charset;
            result.HtmlEncoding = eml_message.BodyHtml.ContentTransferEncoding;

            result.TextBody = eml_message.BodyText.Text;
            result.TextCharset = eml_message.BodyText.Charset;
            result.TextEncoding = eml_message.BodyText.ContentTransferEncoding;

            result.ToXml(out_file_path);
        }
Esempio n. 12
0
        internal async Task<string> ComposeAndSendMailAsync(string user,
                                                            string pass,
                                                            string subject,
                                                           string bodyContent,
                                                           string recipients)
        {
            MailSystem.Message message = new MailSystem.Message();
            message.From = new MailSystem.Address(user);
            string[] toEmails = recipients.Split(';');
            foreach (string mailRecepient in toEmails)
            {
                message.To.Add(mailRecepient);
            }
            message.Subject = subject;

            //message.BodyHtml.Text = "This is some html <b>content</b>";
            message.BodyText.Text = bodyContent;
            bool result = ActiveUp.Net.Mail.SmtpClient.SendSsl(message,
               ConfigurationManager.AppSettings["GmailHost"],
               int.Parse(ConfigurationManager.AppSettings["GmailPort"]),
               user,
               pass,
               MailSystem.SaslMechanism.Login);

            if (result) return "1";
            return "-1";
        }
        private void _bRetrieveSpecificMessage_Click(object sender, EventArgs e)
        {
            // We create Imap client
            Imap4Client imap = new Imap4Client();

            try
            {
                // We connect to the imap4 server
                imap.Connect(_tbImap4Server.Text);

                this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text));

                // Login to mail box
                imap.Login(_tbUserName.Text, _tbPassword.Text);

                this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text));

                Mailbox inbox = imap.SelectMailbox("inbox");
                if (inbox.MessageCount > 0)
                {
                    for (int i = 1; i < inbox.MessageCount + 1; i++)
                    {
                        ActiveUp.Net.Mail.Message message = inbox.Fetch.MessageObject(i);

                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = i.ToString("0000");
                        lvi.SubItems.AddRange(new string[] { message.Subject });
                        lvi.Tag = message;

                        _lvMessages.Items.Add(lvi);

                        this.AddLogEntry(string.Format("{3} Subject: {0} From :{1} Message Body {2}"
                                                       , message.Subject, message.From.Email, message.BodyText, i.ToString("0000")));
                    }
                }

                else
                {
                    this.AddLogEntry("There is no message in the imap4 account");
                }
            }

            catch (Imap4Exception iex)
            {
                this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (imap.IsConnected)
                {
                    imap.Disconnect();
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Method used for send a message.
        /// </summary>
        /// <param name="recipient">The recipients email.</param>
        /// <param name="subject">The message subject.</param>
        /// <param name="body">The message body.</param>
        /// <param name="attachments">The message attachements.</param>
        public void SendMessage(string recipient, string subject, string body, string[] attachments)
        {
            AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo();

            if (accountInfo != null)
            {
                ActiveUp.Net.Mail.Message message = this._smtpController.SendMessage(accountInfo,
                                                                                     recipient, subject, body, attachments);

                if (message != null)
                {
                    MailMessage mailMessage = new MailMessage();
                    mailMessage.SentDate = DateTime.Now;
                    mailMessage.From     = accountInfo.EmailAddress;
                    mailMessage.To       = recipient;
                    mailMessage.Subject  = subject;
                    mailMessage.Read     = true;
                    mailMessage.Id       = message.MessageId;

                    this.CreateMessageBodyFile(mailMessage, message, Constants.SentItems);
                    this._storeSent.Messages.Add(mailMessage);
                    this.SaveMailMessages(Constants.SentItems, this._storeSent.Messages);
                }
            }
        }
Esempio n. 15
0
        private void _bDomainKey_Click(object sender, EventArgs e)
        {
            // We instantiate the pop3 client.
            Pop3Client pop = new Pop3Client();

            try
            {
                this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text));

                // Connect to the pop3 client
                pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);

                if (pop.MessageCount > 0)
                {
                    //Retrive a message at a particulat index
                    ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1);
                    if (message.HasDomainKeySignature)
                    {
                        bool signatureValid = message.Signatures.DomainKeys.Verify();

                        if (signatureValid)
                        {
                            this.AddLogEntry("The domain key signature is valid.");
                        }
                        else
                        {
                            this.AddLogEntry("The domain key signature is invalid.");
                        }
                    }
                    else
                    {
                        this.AddLogEntry("The message hasn't domain key signature.");
                    }
                }

                else
                {
                    this.AddLogEntry("There is no messages in the pop3 account.");
                }
            }

            catch (Pop3Exception pexp)
            {
                this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (pop.IsConnected)
                {
                    pop.Disconnect();
                }
            }
        }
 public abstract void HandleRetrievedMessage(MailBox mailbox,
     Message message,
     MailMessageItem message_item,
     int folder_id,
     string uidl,
     string md5_hash,
     bool unread,
     int[] tags_ids);
Esempio n. 17
0
        private string ConvertUniversalTime(ActiveUp.Net.Mail.Message mail)
        {
            DateTime dtOfThisMail = DateTime.Parse(mail.HeaderFields["date"]);

            dtOfThisMail = DateTime.SpecifyKind(dtOfThisMail, DateTimeKind.Local);
            dtOfThisMail = dtOfThisMail.ToUniversalTime();
            return(dtOfThisMail.ToString());
        }
Esempio n. 18
0
 internal IEnumerable<string> Einplanungsemailadressen_sammeln(Message msg)
 {
     return msg.To
               .Union(msg.Cc)
               .Union(msg.Bcc)
               .Where(empfänger => empfänger.Email.ToLower().EndsWith("@" + _config["mailserver_domain"]))
               .Select(empfänger => empfänger.Email);
 }
        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 add the embedded objets.
            string bodyHtml = string.Empty;

            for (int i = 0; i < _lvEmbeddedObject.Items.Count; i++)
            {
                message.EmbeddedObjects.Add((string)((Utils.ItemTag)_lvEmbeddedObject.Items[i]).Tag, true);
                bodyHtml += "<img src = \"cid:" + message.EmbeddedObjects[i].ContentId + "\" />";
            }
            message.Send("mail.example.com", 25, "*****@*****.**", "userpassword", SaslMechanism.CramMd5);

            message.BodyHtml.Format = BodyFormat.Html;
            if (bodyHtml.Length > 0)
            {
                message.BodyHtml.Text = bodyHtml;
            }
            else
            {
                message.BodyHtml.Text = "The message doens't contain embedded objects.";
            }

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }
        }
Esempio n. 20
0
        private void messagesExplorerListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.messageRfc822RawTextbox.Text = this.messagesExplorerListBox.SelectedItem.ToString();

            ActiveUp.Net.Mail.Message message = ActiveUp.Net.Mail.Parser.ParseMessage(this.messageRfc822RawTextbox.Text);
            this.messageDetailObjectExplorer.SelectedObject = message;
            _selectedMessage = message;
            this.dataGridView1.DataSource = message.Attachments;
        }
        private void _bRetrieveSpecificMessage_Click(object sender, EventArgs e)
        {
            // We instantiate the pop3 client.
            Pop3Client pop = new Pop3Client();

            try
            {
                _lvMessages.Items.Clear();

                this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text));

                // Connect to the pop3 client
                pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);

                if (pop.MessageCount > 0)
                {
                    //Retrive a messaheader at a particulat index (index 1 in this sample)
                    for (int i = 1; i < pop.MessageCount + 1; i++)
                    {
                        ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(i);

                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = i.ToString("0000");
                        lvi.SubItems.AddRange(new string[] { message.Subject });
                        lvi.Tag = message;

                        _lvMessages.Items.Add(lvi);

                        this.AddLogEntry(string.Format("{3} Subject: {0} From :{1} Message Body {2}"
                                                       , message.Subject, message.From.Email, message.BodyText, i.ToString("0000")));
                    }
                }

                else
                {
                    this.AddLogEntry("There is no message in this pop3 account");
                }
            }

            catch (Pop3Exception pexp)
            {
                this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (pop.IsConnected)
                {
                    pop.Disconnect();
                }
            }
        }
        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 add the embedded objets.
            string bodyHtml = string.Empty;    
            for (int i = 0; i < _lvEmbeddedObject.Items.Count; i++)
            {
                message.EmbeddedObjects.Add((string)((Utils.ItemTag)_lvEmbeddedObject.Items[i]).Tag, true);
                bodyHtml += "<img src = \"cid:" + message.EmbeddedObjects[i].ContentId + "\" />";
            }
            message.Send("mail.example.com", 25, "*****@*****.**", "userpassword", SaslMechanism.CramMd5);

            message.BodyHtml.Format = BodyFormat.Html;
            if (bodyHtml.Length > 0)
            {
                message.BodyHtml.Text = bodyHtml;
            }
            else
            {
                message.BodyHtml.Text = "The message doens't contain embedded objects.";
            }

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }

        }
Esempio n. 23
0
 protected int GetAttachmentFromMail(string SavePath, ActiveUp.Net.Mail.Message mail)
 {
     foreach (MimePart att in mail.Attachments)
     {
         string fileSavePath = Path.Combine(SavePath, (mail.From.Email + ConvertUniversalTime(mail) + "$" + ReplaceInvalidFilenameChars(att.Filename)).Replace("/", "").Replace(":", "").Replace(" ", ""));
         attachmentNames.Add(fileSavePath);
         File.WriteAllBytes(fileSavePath, att.BinaryContent);
     }
     return(1);
 }
        private void _bRetrieveSpecificMessage_Click(object sender, EventArgs e)
        {
            // We create nntp client object.
            NntpClient nntp = new NntpClient();

            try
            {
                // We connect to the nntp server.
                nntp.Connect(_tbNntpServer.Text);

                // Get a news group on the server
                NewsGroup group = nntp.SelectGroup(_tbNewsgroup.Text);

                if (group.ArticleCount > 0)
                {
                    for (int i = 1; i < group.ArticleCount + 1; i++)
                    {
                        ActiveUp.Net.Mail.Message message = group.RetrieveArticleObject(i);

                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = i.ToString("0000");
                        lvi.SubItems.AddRange(new string[] { message.Subject });
                        lvi.Tag = message;

                        _lvMessages.Items.Add(lvi);

                        this.AddLogEntry(string.Format("{1} Subject: {0}"
                                                       , message.Subject, i.ToString("0000")));
                    }
                }

                else
                {
                    this.AddLogEntry("There is no message in the newsgroup.");
                }
            }

            catch (NntpException pexp)
            {
                this.AddLogEntry(string.Format("Nntp Error: {0}", pexp.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (nntp.IsConnected)
                {
                    nntp.Disconnect();;
                }
            }
        }
        private void _bCheckBounce_Click(object sender, EventArgs e)
        {
            // We instantiate the pop3 client.
            Pop3Client pop = new Pop3Client();

            try
            {
                this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text));

                // We connect to the pop3 client
                pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);

                if (pop.MessageCount > 0)
                {
                    // We retrive a message at a particular index (index 1 in this sample)
                    ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1);

                    BounceResult br = message.GetBounceStatus();

                    if (br.Level == 3)
                    {
                        this.AddLogEntry(string.Format("Message sent to  {0} is bounced", br.Email));
                    }

                    else
                    {
                        this.AddLogEntry(string.Format("Message sent to {0} is not bounced", br.Email));
                    }
                }

                else
                {
                    this.AddLogEntry("There is no message in this pop3 account");
                }
            }

            catch (Pop3Exception pexp)
            {
                this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (pop.IsConnected)
                {
                    pop.Disconnect();
                }
            }
        }
    	public ActiveUp.Net.Mail.Message buildMessageObject()
    	{
    		_message = new ActiveUp.Net.Mail.Message();
			_message.From = new Address(From_Email,From_Name);
			foreach(var item in To)    		
				_message.To.Add(new Address(item.Key,item.Value)); //syntax: (email, name)
	
			_message.Subject = Subject;
			_message.BodyText.Text = Body.line().line() + Body_SpoofEmailAlertFooter;
			return _message;
    	}
        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 return recipient email
            message.ReturnReceipt.Email = this._tbReturnReceipt.Text;

            // We assign the confirmation read email
            message.ConfirmRead.Email = this._tbConfirmReadEmail.Text;

            // We assign the reply to email
            message.ReplyTo.Email = this._tbReplyTo.Text;

            // We assign the comments
            message.Comments = this._tbComments.Text;

            // We assign the mime type.
            message.ContentType.MimeType = "text/html";

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

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

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

            try
            {
                SmtpClient.Send(message, this._tbSmtpServer.Text);

                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));
            }
        }
        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 return recipient email
            message.ReturnReceipt.Email = this._tbReturnReceipt.Text;

            // We assign the confirmation read email
            message.ConfirmRead.Email = this._tbConfirmReadEmail.Text;

            // We assign the reply to email
            message.ReplyTo.Email = this._tbReplyTo.Text;

            // We assign the comments
            message.Comments = this._tbComments.Text;

            // We assign the mime type.
            message.ContentType.MimeType = "text/html";

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

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

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }
        }
Esempio n. 29
0
        protected List <string> GetAttachmentFileNameFromMail(string SavePath, ActiveUp.Net.Mail.Message mail)
        {
            List <string> attachNames = new List <string>();

            foreach (MimePart att in mail.Attachments)
            {
                string fileSavePath = Path.Combine(SavePath, (mail.From.Email + ConvertUniversalTime(mail) + "$" + ReplaceInvalidFilenameChars(att.Filename)).Replace("/", "").Replace(":", "").Replace(" ", ""));
                attachNames.Add(fileSavePath);
            }
            return(attachNames);
        }
Esempio n. 30
0
        internal static Message MapOutboxToMailMessage(IDataRecord dr)
        {
            Encoding encoding = Codec.GetEncoding("iso-8859-1");

            ActiveUp.Net.Mail.Message msg = new ActiveUp.Net.Mail.Message();
            msg.Charset = encoding.BodyName;
            msg.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            msg.ContentType             = new ContentType();
            string appo = null;

            if (!String.IsNullOrEmpty(appo = dr.GetString("MAIL_CCN")))
            {
                msg.Bcc = Parser.ParseAddresses(appo);
                appo    = null;
            }
            if (!String.IsNullOrEmpty(appo = dr.GetString("MAIL_CC")))
            {
                msg.Cc = Parser.ParseAddresses(appo);
                appo   = null;
            }
            if (!String.IsNullOrEmpty(appo = dr.GetString("MAIL_TO")))
            {
                msg.To = Parser.ParseAddresses(appo);
                appo   = null;
            }
            if (!String.IsNullOrEmpty(appo = dr.GetString("MAIL_TEXT")))
            {
                msg.BodyHtml      = new ActiveUp.Net.Mail.MimeBody(ActiveUp.Net.Mail.BodyFormat.Html);
                msg.BodyHtml.Text = appo;
                appo = null;
            }
            msg.From    = Parser.ParseAddress(dr.GetString("MAIL_SENDER"));
            msg.Id      = (int)dr.GetInt64("ID_MAIL");
            msg.Subject = dr.GetString("MAIL_SUBJECT");

            if (!String.IsNullOrEmpty(appo = dr.GetString("ALLEG")))
            {
                var mime = appo.Split(new char[] { ';' }).Select(x =>
                {
                    ActiveUp.Net.Mail.MimePart mp = new ActiveUp.Net.Mail.MimePart();
                    string[] pp      = x.Split('#');
                    mp.ContentId     = pp[0];
                    mp.Filename      = pp[1];
                    mp.ParentMessage = msg;
                    return(mp);
                });
                foreach (var mm in mime)
                {
                    msg.Attachments.Add(mm);
                }
            }
            return(msg);
        }
Esempio n. 31
0
        public void GmailSubjectEncodingTest()
        {
            Message message = new Message();
            message.From = new Address("*****@*****.**", "John Doe");
            message.To.Add("[youraccounthere]@gmail.com", "Jean Dupont");
            message.Subject = Codec.RFC2047Encode("Je suis Liégeois et je suis prêt à rencontrer Asger Jørnow", "iso-8859-1");

            message.BodyHtml.Text = "This is some html <b>content</b>";
            message.BodyText.Text = "This is some plain/text content";

            SmtpClient.SendSsl(message, "smtp.gmail.com", 465, "[putyourloginhere]", "[putyourpasshere]", SaslMechanism.Login);
        }
 public ActiveUp.Net.Mail.Message buildMessageObject()
 {
     _message      = new ActiveUp.Net.Mail.Message();
     _message.From = new Address(From_Email, From_Name);
     foreach (var item in To)
     {
         _message.To.Add(new Address(item.Key, item.Value));                //syntax: (email, name)
     }
     _message.Subject       = Subject;
     _message.BodyText.Text = Body.line().line() + Body_SpoofEmailAlertFooter;
     return(_message);
 }
Esempio n. 33
0
        private void InserirEmail(ActiveUp.Net.Mail.Message mes)
        {
            string strConexao = ConfigurationManager.ConnectionStrings["conexao"].ToString();
            Guid   IdEmail    = Guid.NewGuid();

            using (NpgsqlConnection con = new NpgsqlConnection(strConexao))
            {
                con.Open();
                using (var trans = con.BeginTransaction())
                {
                    try
                    {
                        //Insere o e-mail
                        NpgsqlCommand cmd = new NpgsqlCommand();
                        cmd.Connection  = con;
                        cmd.Transaction = trans;
                        cmd.CommandText = "insert into email (id, email_title, email_text, email_date ) values (@id, @email_title, @email_text, @email_date)";
                        cmd.Parameters.AddWithValue("id", IdEmail.ToString());
                        cmd.Parameters.AddWithValue("email_title", mes.Subject);
                        cmd.Parameters.AddWithValue("email_text", mes.BodyText.Text);
                        cmd.Parameters.AddWithValue("email_date", mes.Date);
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();

                        //Insere o sender
                        cmd.CommandText = "insert into sender_email (id, emailid, email_sender) values (@id, @emailid, @email_sender)";
                        cmd.Parameters.AddWithValue("id", Guid.NewGuid().ToString());
                        cmd.Parameters.AddWithValue("emailid", IdEmail.ToString());
                        cmd.Parameters.AddWithValue("email_sender", mes.From.Email);
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();

                        //Insere o To
                        foreach (var mail in mes.To)
                        {
                            cmd.CommandText = "insert into sender_to (id, emailid, email_to) values (@id, @emailid, @email_to)";
                            cmd.Parameters.AddWithValue("id", Guid.NewGuid().ToString());
                            cmd.Parameters.AddWithValue("emailid", IdEmail.ToString());
                            cmd.Parameters.AddWithValue("email_to", mail.Email);
                            cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();
                        }

                        trans.Commit();
                    }
                    catch (Exception e)
                    {
                        trans.Rollback();
                    }
                }
            }
        }
Esempio n. 34
0
        public static void SendMail(string MailMsg, List <string> MailTo, List <string> MailCc, List <string> MailBcc, string Subject, byte[] Attachment, string AttachmentExt)
        {
            try
            {
                //Smtp Settings
                string mailhost = ConfigurationManager.AppSettings["Host"];

                string mailusername = ConfigurationManager.AppSettings["MailUserName"];
                string mailpassword = ConfigurationManager.AppSettings["MailPassword"];
                string mailport     = ConfigurationManager.AppSettings["MailPort"];
                string enablessl    = ConfigurationManager.AppSettings["EnableSsl"];

                //Mail Settings
                string mailfrom = ConfigurationManager.AppSettings["MailFromAddress"];
                ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();
                message.From = new Address(mailfrom);
                foreach (string mailto in MailTo)
                {
                    message.To.Add(mailto, "");
                }
                foreach (string mailcc in MailCc)
                {
                    message.Cc.Add(mailcc, "");
                }
                foreach (string mailbcc in MailBcc)
                {
                    message.Bcc.Add(mailbcc, "");
                }
                message.Subject = Subject;

                message.BodyHtml.Text = MailMsg;

                if (Attachment != null)
                {
                    MimePart m = new MimePart(Attachment, AttachmentExt);
                    message.Attachments.Add(m);
                }

                int port = 25;
                // System.Net.ServicePointManager.Expect100Continue = false;
                if (!Int32.TryParse(mailport, out port))
                {
                    port = 25;
                }

                SmtpClient.SendSsl(message, mailhost, port, mailusername, mailpassword, SaslMechanism.Login);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 35
0
        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;

            // It is required to build the mime part tree before signing
            message.BuildMimePartTree();

            if (_tbCertificate.Text != string.Empty)
            {
                CmsSigner signer = new CmsSigner(new X509Certificate2(_tbCertificate.Text));

                // Here we only want the signer's certificate to be sent along. Not the whole chain.
                signer.IncludeOption = X509IncludeOption.EndCertOnly;

                message.SmimeAttachSignatureBy(signer);
            }

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

            try
            {
                SmtpClient.Send(message, this._tbSmtpServer.Text);

                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));
            }
        }
        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;

            // It is required to build the mime part tree before signing
            message.BuildMimePartTree();

            if (_tbCertificate.Text != string.Empty)
            {
                CmsSigner signer = new CmsSigner(new X509Certificate2(_tbCertificate.Text));

                // Here we only want the signer's certificate to be sent along. Not the whole chain.
                signer.IncludeOption = X509IncludeOption.EndCertOnly;

                message.SmimeAttachSignatureBy(signer);
            }

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            if (this.attachmentsListbox.Items.Count > 0)
            {
                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.fromEmailTextbox.Text;

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

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

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

                // We now add each attachments
                foreach (string attachmentPath in this.attachmentsListbox.Items)
                {
                    message.Attachments.Add(attachmentPath, false);
                }

                message.BuildMimePartTree();

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

                try
                {
                    message.Send(this.smtpServerAddressTextbox.Text);

                    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));
                }
            }
            else
            {
                MessageBox.Show("Please add an attachment before sending this test message.");
            }
        }
Esempio n. 38
0
        private void sendTestMessageButton_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Sending test message using DirectSend()");

            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();
            message.From.Email = this.emailAddressTextbox.Text;
            message.To.Add(this.emailAddressTextbox.Text);
            message.Subject       = "This is a notification test.";
            message.BodyText.Text = "This is a notification test.";
            message.DirectSend();

            this.AddLogEntry("Notification test message sent.");
        }
        private void _bSendMessage_Click(object sender, EventArgs e)
        {
			if (this._lvAttachments.Items.Count > 0)
			{
				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;

				// We now add each attachments
				foreach (string attachmentPath in this._lvAttachments.Items)
				{
					message.Attachments.Add(attachmentPath, false);
				}

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

				try
				{
					message.Send(this._tbSmtpServer.Text);

					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));
				}
			}

			else
			{
				MessageBox.Show("Please add an attachment before sending this test message.");
			}
        }
Esempio n. 40
0
        private void useSelectedButton_Click(object sender, EventArgs e)
        {
            ActiveUp.Net.Mail.Pop3Client client = new ActiveUp.Net.Mail.Pop3Client();
            client.Connect(this.pop3ServerHostTextbox.Text, Convert.ToInt32(this.pop3ServerPortNumericUpDown.Value),
                           this.pop3ServerUsernameTextbox.Text, this.pop3ServerPasswordTextbox.Text);

            Header gridSelection = (Header)this.dataGridView1.SelectedRows[0].DataBoundItem;

            _selectedMessage = client.RetrieveMessageObject(gridSelection.IndexOnServer);

            client.Close();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 41
0
        private void useSelectedButton_Click(object sender, EventArgs e)
        {
            ActiveUp.Net.Mail.Pop3Client client = new ActiveUp.Net.Mail.Pop3Client();
            client.Connect(this.pop3ServerHostTextbox.Text, Convert.ToInt32(this.pop3ServerPortNumericUpDown.Value),
                this.pop3ServerUsernameTextbox.Text, this.pop3ServerPasswordTextbox.Text);

            Header gridSelection = (Header)this.dataGridView1.SelectedRows[0].DataBoundItem;

            _selectedMessage = client.RetrieveMessageObject(gridSelection.IndexOnServer);

            client.Close();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 42
0
        /// <summary>
        /// Save event handler.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The event arguments.</param>
        private void toolStripButtonSave_Click(object sender, EventArgs e)
        {
            string currentDir = Directory.GetCurrentDirectory();
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "ActiveUp Email Files |*.eml";
            DialogResult dr = saveDialog.ShowDialog();
            if (dr == DialogResult.OK)
            {
                ActiveUp.Net.Mail.Message message = this.CreateMessage();
                message.StoreToFile(saveDialog.FileName);
            }

            Directory.SetCurrentDirectory(currentDir);
        }
Esempio n. 43
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Valida os campos
            if (string.IsNullOrEmpty(txtEnderecoEmail.Text))
            {
                MessageBox.Show("O endereço de e-mail deve ser informado!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            if (string.IsNullOrEmpty(txtSenha.Text))
            {
                MessageBox.Show("A senha deve ser informada!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            if (string.IsNullOrEmpty(txtNomeCaixa.Text))
            {
                MessageBox.Show("O nome da caixa de e-mails deve ser informado!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            if (string.IsNullOrEmpty(txtQtdEmails.Text))
            {
                MessageBox.Show("A quantidade de e-mails a serem buscados deve ser informada!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            //Conecta na conta de e-mail informada
            var mailRepository = new MailRepository(
                "imap.gmail.com",
                993,
                true,
                txtEnderecoEmail.Text,
                txtSenha.Text
                );


            Mailbox mail = mailRepository.GetMailBox(txtNomeCaixa.Text);

            barraProgresso.Visible = true;
            barraProgresso.Minimum = 0;
            barraProgresso.Maximum = (mail.MessageCount + 1);
            barraProgresso.Value   = 1;

            for (int n = 1; n < mail.MessageCount + 1; n++)
            {
                ActiveUp.Net.Mail.Message newMessage = mailRepository.GetMail(mail, n);
                InserirEmail(newMessage);
                barraProgresso.Value++;
                this.Refresh();
            }
            barraProgresso.Visible = false;
        }
Esempio n. 44
0
        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();

            try
            {
                // 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;

                // It is required to build the mime part tree before encrypting
                message.BuildMimePartTree();

                // Encrypt the message. You need the recipient(s) certificate(s) (with public key only).
                X509Certificate2 recipientCertificate = new X509Certificate2(_tbRecipientCertificate.Text);

                CmsRecipient recipient = new CmsRecipient(recipientCertificate);

                message.SmimeEnvelopeAndEncryptFor(recipient);

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

                message.Send(this._tbSmtpServer.Text);

                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));
            }
        }
Esempio n. 45
0
        /// <summary>
        /// The read e-mail command action.
        /// Uses the password and email to connect to the mailbox using IMAP v4 security and reads the e-mails.
        /// </summary>
        public void ReadEmailCommandAction()
        {
            string msg = "Getting Mail from '" + _emailAddress + "' with password '" + _password + "'";

            MessageBox.Show(msg);

            string selectedMailBox = "INBOX";

            using (var clientImap4 = new Imap4Client())
            {
                try
                {
                    clientImap4.ConnectSsl(ImapServerAddress, ImapPort);

                    // Make log in and load all MailBox.
                    clientImap4.Login(_emailAddress, _password);

                    var mailBox = clientImap4.SelectMailbox(selectedMailBox);

                    string messageItemText = string.Empty;
                    foreach (int messageId in mailBox.Search("ALL").AsEnumerable().OrderByDescending(x => x))
                    {
                        byte[] message = mailBox.Fetch.Message(messageId);
                        ActiveUp.Net.Mail.Message imapMessage = Parser.ParseMessage(message);

                        messageItemText +=
                            "From: " + imapMessage.From.Name + ", Subject: " + imapMessage.Subject + "\n";

                        if (imapMessage.Subject.ToLower().Contains("tallies"))
                        {
                            messageItemText += "\n";

                            messageItemText += imapMessage.BodyText.Text;

                            messageItemText += "\n";
                        }
                    }

                    MailItemsText = messageItemText;
                    clientImap4.Disconnect();
                }
                catch (Exception e)
                {
                    string error = e.Message + " : " + e.InnerException;
                    MessageBox.Show(error);
                }
            }
        }
        public void SaveMailContacts(int tenant, string user, Message message)
        {
            try
            {
                var contacts = new AddressCollection();
                contacts.AddRange(message.To);
                contacts.AddRange(message.Cc);
                contacts.AddRange(message.Bcc);

                foreach (var contact in contacts)
                {
                    contact.Name = !String.IsNullOrEmpty(contact.Name) ? Codec.RFC2047Decode(contact.Name) : String.Empty;
                }

                var contactsList = contacts.Distinct().ToList();

                using (var db = GetDb())
                {
                    var validContacts = (from contact in contactsList
                                         where MailContactExists(db, tenant, user, contact.Name, contact.Email) < 1
                                         select contact).ToList();

                    if (!validContacts.Any()) return;

                    var lastModified = DateTime.UtcNow;

                    var insertQuery = new SqlInsert(ContactsTable.name)
                        .InColumns(ContactsTable.Columns.id_user,
                                   ContactsTable.Columns.id_tenant,
                                   ContactsTable.Columns.name,
                                   ContactsTable.Columns.address,
                                   ContactsTable.Columns.last_modified);

                    validContacts
                        .ForEach(contact =>
                                 insertQuery
                                     .Values(user, tenant, contact.Name, contact.Email, lastModified));

                    db.ExecuteNonQuery(insertQuery);
                }
            }
            catch (Exception e)
            {
                _log.Error("SaveMailContacts(tenant={0}, userId='{1}', mail_id={2}) Exception:\r\n{3}\r\n",
                          tenant, user, message.Id, e.ToString());
            }
        }
        public static Signature Parse(string input, Message signedMessage)
        {
            Signature signature;
            if (signedMessage != null) signature = new Signature(signedMessage);
            else signature = new Signature();

            MatchCollection matches = Regex.Matches(input, @"[a-zA-Z]+=[^;]+(?=(;|\Z))");
            ActiveUp.Net.Mail.Logger.AddEntry(matches.Count.ToString());
            foreach (Match m in matches)
            {
                string tag = m.Value.Substring(0,m.Value.IndexOf('='));
                //TODO: This is an insane bug fix. Please try to parse 200711050949465352.tmp with the line commented
                //string value = m.Value.Substring(m.Value.IndexOf('=')+1);
                string value = m.Value.Substring(m.Value.IndexOf('=')+1).Split(',')[0];
                if (tag.Equals("a")) signature._a = value;
                else if (tag.Equals("b"))
                {
                    value = value.Trim('\r', '\n').Replace(" ", "");
                    //while ((value.Length % 4) != 0) value += "=";
                    signature._b64 = value.Replace(" ", "").Replace("\t", "").Replace("\r\n", "");
                        signature._b = Convert.FromBase64String(signature._b64);

                    //if (signature._b64[signature._b64.Length - 2] == '=' &&
                    //    signature._b64[signature._b64.Length - 1] == '=')
                    //{
                    //    signature._b64 = signature._b64.Substring(0, signature._b64.Length - 1);
                    //}

                    
                }
                else if (tag.Equals("c"))
                {
                    if (value.Equals("nofws")) signature._c = CanonicalizationAlgorithm.NoFws;
                    else if (value.Equals("simple")) signature._c = CanonicalizationAlgorithm.Simple;
                    else signature._c = CanonicalizationAlgorithm.Other;
                }
                else if (tag.Equals("d")) signature._d = value;
                else if (tag.Equals("s")) signature._s = value;
                else if (tag.Equals("q"))
                {
                    if (value.Equals("dns")) signature._q = QueryMethod.Dns;
                    else signature._q = QueryMethod.Other;
                }
                else if (tag.Equals("h")) signature._h = value.Split(':');
            }
            return signature;
        }
        public override void HandleRetrievedMessage(MailBox mailbox, Message message , MailMessageItem message_item, int folder_id, string uidl, string md5_hash, bool unread,
                                                    int[] tags_ids)
        {
            if (string.IsNullOrEmpty(mailbox.EMailInFolder))
                return;

            try
            {

                foreach (var attachment in message_item.Attachments)
                {
                    using (var file = AttachmentManager.GetAttachmentStream(attachment))
                    {
                        log.Debug("EmailInMessageHandler HandleRetrievedMessage file name: {0}, folder id: {1}",
                                  file.FileName, mailbox.EMailInFolder);
                        var uploaded_file_id = FilesUploader.UploadToFiles(file.FileStream, file.FileName,
                                                                           attachment.contentType, mailbox.EMailInFolder,
                                                                           new Guid(mailbox.UserId), log);
                        if (uploaded_file_id < 0)
                        {
                            log.Error("EmailInMessageHandler HandleRetrievedMessage uploaded_file_id < 0");
                        }
                    }
                }

            }
            catch (WebException we)
            {
                var status_code = ((HttpWebResponse) we.Response).StatusCode;

                if (status_code == HttpStatusCode.NotFound || status_code == HttpStatusCode.Forbidden)
                {
                    MailBoxManager.CreateUploadToDocumentsFailureAlert(mailbox.TenantId, mailbox.UserId,
                                                                       mailbox.MailBoxId,
                                                                       (status_code == HttpStatusCode.NotFound)
                                                                           ? MailBoxManager.UploadToDocumentsErrorType
                                                                                           .FolderNotFound
                                                                           : MailBoxManager.UploadToDocumentsErrorType
                                                                                           .AccessDenied);

                    MailBoxManager.SetMailboxEmailInFolder(mailbox.TenantId, mailbox.UserId, mailbox.MailBoxId, null);
                    mailbox.EMailInFolder = null;
                }

                throw;
            }
        }
        private void _tbSendMessage_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;

            // We use base 64 encoding
            message.ContentTransferEncoding = (ContentTransferEncoding)Enum.Parse(typeof(ContentTransferEncoding), (string)_comboTransfertEncoding.SelectedItem, true); 

            // We set the charset
            message.Charset = ((ComboItem)_comboCharset.SelectedItem).Value;

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }
        }
Esempio n. 50
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 _tbSendMessage_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;

            // We use base 64 encoding
            message.ContentTransferEncoding = ContentTransferEncoding.Base64;   

            message.BuildMimePartTree();

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }
        }
        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;

            //Add the recipients e mail ids
            foreach (ListViewItem lvi in _lvToEmail.Items)
            {
                message.To.Add(lvi.Text);
            }

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

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

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

            try
            {
                message.Send(this._tbSmtpServer.Text);

                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));
            }
                  
        }
        private void sendMessageButton_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.fromEmailTextbox.Text;

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

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

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

            ServerCollection smtpServers = new ServerCollection();
            smtpServers.Add(this.smtpServerAddressTextbox.Text);
            smtpServers.Add(this.backupSmtpServerAddressTextbox.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));
            }
        }
Esempio n. 54
0
        /// <summary>
        /// Appends the specified mail message.
        /// </summary>
        /// <param name="mailMessage">The mail message.</param>
        public void Append(MailMessage<MailMessageHeader> mailMessage)
        {
            Imap4Client imap4Client = null;

            try
            {
                imap4Client = _imapClientProvider.GetImapClient();

                var mailBox = imap4Client.SelectMailbox(SentItemMailBox);

                var imapMail = new Message
                    {
                        From = new Address(mailMessage.Header.FromAddress, mailMessage.Header.FromName),
                        To = new AddressCollection { new Address(mailMessage.Header.ToAddress, mailMessage.Header.ToName) },
                        Subject = mailMessage.Header.Subject,
                        BodyText = new MimeBody ( BodyFormat.Text ) { Text = mailMessage.BodyText }
                    };

                mailMessage.Attachments.ForEach(
                    p =>
                        {
                            if (p.ContentBytes != null)
                            {
                                imapMail.Attachments.Add(( byte[] )p.ContentBytes, p.FileName);
                            }
                            else
                            {
                                imapMail.Attachments.Add(Encoding.Default.GetBytes(( string )p.ContentString), p.FileName);
                            }
                        });

                mailBox.Append(imapMail); // Do not use messageToAdd.Append(mailBox), it does not work
            }
            finally
            {
                if (imap4Client != null && imap4Client.IsConnected)
                {
                    imap4Client.Disconnect();
                }
            }
        }
Esempio n. 55
0
        private void sendEmail(object sender, System.ComponentModel.DoWorkEventArgs e) {
            Message mail = new Message();
            mail.From = new Address(from);
            mail.To.Add(new Address(to));

            mail.Subject = title;

            mail.Priority = MessagePriority.Normal;

            MimeBody body = new MimeBody(BodyFormat.Text);
            body.Text = this.body;
            mail.BodyText = body;

            //            mail  .Headers.Add("Disposition-Notification-To", "<" + email_sender + ">");
            // mail.Attachments.Add(Server.MapPath("/"));

            SmtpClient.DirectSend(mail);


            e.Result = EmailResponse.EmailSent;
        }
        private void sendMessageButton_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.fromEmailTextbox.Text;

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

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

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

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

            try
            {
                SmtpClient smtpClient = new SmtpClient();

                SslHandShake handShake = new SslHandShake("mail.activeup.com", System.Security.Authentication.SslProtocols.Ssl3);
                handShake.ServerCertificateValidationCallback = MyServerCertificateValidationCallback;

                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));
            }
        }
        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;

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

            try
            {
                //Send the message specifying the address of the smtp server, asynchronously
                //SendingDone method gets the notification once the message sending is done.
                message.BeginSend(this._tbSmtpServer.Text, new AsyncCallback(this.SendingDone));
            }

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

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
        public static void SaveMailContacts(IDbManager db, int tenant, string user, Message message, ILogger log)
        {
            try
            {
                var contacts = new AddressCollection {message.From};
                contacts.AddRange(message.To);
                contacts.AddRange(message.Cc);
                contacts.AddRange(message.Bcc);

                var valid_contacts = (from contact in contacts
                                      where MailContactExists(db, tenant, user, contact.Name, contact.Email) < 1
                                      select contact).ToList();

                if (!valid_contacts.Any()) return;

                var last_modified = DateTime.Now;

                var insert_query = new SqlInsert(ContactsTable.name)
                    .InColumns(ContactsTable.Columns.id_user,
                               ContactsTable.Columns.id_tenant,
                               ContactsTable.Columns.name,
                               ContactsTable.Columns.address,
                               ContactsTable.Columns.last_modified);

                valid_contacts
                    .ForEach(contact =>
                             insert_query
                                 .Values(user, tenant, contact.Name, contact.Email, last_modified));

                db.ExecuteNonQuery(insert_query);
            }
            catch (Exception e)
            {
                log.Warn("SaveMailContacts(tenant={0}, userId='{1}', mail_id={2}) Exception:\r\n{3}\r\n",
                          tenant, user, message.Id, e.ToString());
            }
        }
Esempio n. 59
0
        private void _bPostMessage_Click(object sender, EventArgs e)
        {
            // We create nntp client object.
            NntpClient nntp = new NntpClient();

            try
            {
                // We connect to the nntp server.
                nntp.Connect(_tbNntpServer.Text);

                // We create the message to post.
                ActiveUp.Net.Mail.Message msg = new ActiveUp.Net.Mail.Message();
                msg.Subject = _tbSubject.Text;
                msg.BodyText.Text = _tbBody.Text;
                msg.To.Add(_tbNewsgroup.Text);
                nntp.Post(msg);  
            }

            catch (NntpException pexp)
            {
                this.AddLogEntry(string.Format("Nntp Error: {0}", pexp.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (nntp.IsConnected)
                {
                    nntp.Disconnect(); ;
                }
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            // Let us create a data source in this case Hastable that would 
            // used to demonstrate the merging
            // Take the form variables collection as the data source.
            Hashtable dataSource = new Hashtable();
            dataSource.Add("FIRSTNAME", "John");
            dataSource.Add("LASTNAME", "Richards");
            dataSource.Add("MESSAGE", "This is a test mail.");
            dataSource.Add("VAR1", "This is a variable.");

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

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

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

            // We assign the subject
            message.Subject = this.subjectTextbox.Text;
            
            // We create the template.
            System.Text.StringBuilder messageTemplate = new System.Text.StringBuilder();
            messageTemplate.Append("Request posted\n\n");
            messageTemplate.Append("Firstname : $FIRSTNAME$\n");
            messageTemplate.Append("Lastname : $LASTNAME$\n");
            messageTemplate.Append("Message : $MESSAGE$\n");

            message.BodyText.Text = messageTemplate.ToString();

            Merger merger = new Merger();

            // We merge our DataSource
            merger.MergeMessage(message, dataSource, false);

            //Handle the error in case any
            try
            {
                // We send the mail
                message.Send(smtpServerAddressTextbox.Text);

                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));
            }
        }