/// <summary> /// Method for delete message. /// </summary> /// <param name="messageIdentifier">The mail message.</param> /// <param name="mailbox">The mailbox.</param> public void DeleteMessage(MailMessage mailMessage, string mailbox) { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { try { if (accountInfo.MailAccountType == AccountType.POP3) { this._pop3Controller.DeleteMessage(mailMessage.Id); } else if (accountInfo.MailAccountType == AccountType.IMAP) { this._imap4Controller.DeleteMessage(mailMessage.Id, mailbox); } } catch (Exception) { } // add to delete items. if (!mailbox.Equals(Constants.DeletedItems)) { this._storeDelete.Messages.Add(mailMessage); this.SaveMailMessages(Constants.DeletedItems, this._storeDelete.Messages); } } }
/// <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); } } }
/// <summary> /// Button event for set the default mail settings. /// </summary> /// <param name="sender">The sender object.</param> /// <param name="e">The event arguments.</param> private void btnSetDefault_Click(object sender, EventArgs e) { if (lstAccounts.SelectedIndex >= 0) { AccountSettings.AccountInfo accountInfo = (AccountSettings.AccountInfo)(this.lstAccounts.SelectedItem); Facade.GetInstance().SetDefaultAccountInfo(accountInfo); Facade.GetInstance().SaveClientSettings(); } }
/// <summary> /// Button remove event handler. /// </summary> /// <param name="sender">The sender object.</param> /// <param name="e">The event arguments.</param> private void btnRemove_Click(object sender, EventArgs e) { if (lstAccounts.SelectedIndex >= 0) { AccountSettings.AccountInfo accountInfo = (AccountSettings.AccountInfo)(this.lstAccounts.SelectedItem); Facade.GetInstance().DeleteAccountInfo(accountInfo); this.lstAccounts.Items.Remove(accountInfo); } }
/// <summary> /// Button add event click. /// </summary> /// <param name="sender">The sender object.</param> /// <param name="e">The event arguments.</param> private void btnAddAccount_Click(object sender, EventArgs e) { AddAccountWizardForm frmAdd = new AddAccountWizardForm(); if (frmAdd.ShowDialog() == DialogResult.OK) { AccountSettings.AccountInfo accountInfo = frmAdd.NewAccountInfo; Facade.GetInstance().AddAccountInfo(accountInfo); Facade.GetInstance().SaveAccountSettings(); this.lstAccounts.Items.Add(accountInfo); } }
private void AddAccountWizardForm_Load(object sender, EventArgs e) { panelScreen1.Visible = true; panelScreen2.Visible = false; panelScreen3.Visible = false; if (_accInfo == null) { _accInfo = new AccountSettings.AccountInfo(); } ddlAuthenticationType.Items.Clear(); ddlAuthenticationType.Items.AddRange(Enum.GetNames(typeof(EncryptionType))); }
/// <summary> /// Method for disconnect the current protocol. /// </summary> public void Disconnect() { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { if (accountInfo.MailAccountType == AccountType.POP3) { this._pop3Controller.Disconnect(); } else if (accountInfo.MailAccountType == AccountType.IMAP) { this._imap4Controller.Disconnect(); } } }
/// <summary> /// Button properties click. /// </summary> /// <param name="sender">The sender object.</param> /// <param name="e">The event arguments.</param> private void btnProperties_Click(object sender, EventArgs e) { if (lstAccounts.SelectedIndex >= 0) { AccountSettings.AccountInfo accountInfo = (AccountSettings.AccountInfo)(this.lstAccounts.SelectedItem); AddAccountWizardForm frmAdd = new AddAccountWizardForm(); frmAdd.NewAccountInfo = accountInfo; DialogResult dr = frmAdd.ShowDialog(); if (dr == DialogResult.OK) { Facade.GetInstance().SaveAccountSettings(); this.LoadAccoutnSetings(); } } }
/// <summary> /// Get a mail message basend on message identifier. /// </summary> /// <param name="mailMessage">The mail message.</param> /// <param name="mailbox">The mailbox for get the message.</param> /// <returns>The ActiveUp.Net.Mail.Message object.</returns> public ActiveUp.Net.Mail.Message GetMessage(MailMessage mailMessage, string mailbox) { ActiveUp.Net.Mail.Message ret = null; AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { if (accountInfo.MailAccountType == AccountType.POP3) { ret = this._pop3Controller.GetMessage(mailMessage); } else if (accountInfo.MailAccountType == AccountType.IMAP) { ret = this._imap4Controller.GetMessage(mailbox, mailMessage); } } return(ret); }
/// <summary> /// Method for get the message count. /// </summary> /// <param name="mailbox">The mailbox name.</param> /// <returns>The message count number.</returns> public int GetMessageCount(string mailbox) { int messageCount = 0; AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { if (accountInfo.MailAccountType == AccountType.POP3) { messageCount = this._pop3Controller.GetMessageCount(); } else if (accountInfo.MailAccountType == AccountType.IMAP) { messageCount = this._imap4Controller.GetMessageCount(mailbox); } } return(messageCount); }
// Region for Mailboxes folders. #region MailBoxes /// <summary> /// Get all mailbox folders. /// </summary> /// <returns></returns> public MailboxCollection GetAllMailbox() { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); MailboxCollection ret = new MailboxCollection(); if (accountInfo != null) { if (accountInfo.MailAccountType == AccountType.POP3) { // TODO... check if it's possible. //ret = this._pop3Controller.(); } else if (accountInfo.MailAccountType == AccountType.IMAP) { ret = this._imap4Controller.GetAllMailbox(Constants.Inbox); } } return(ret); }
/// <summary> /// Property for get the default account information. /// </summary> /// <returns>The default AccountInfo object.</returns> public AccountSettings.AccountInfo GetDefaultAccountInfo() { AccountSettings.AccountInfo ret = null; foreach (AccountSettings.AccountInfo info in this._accSettings) { if (this._clientSettings.DefaultAccountID == info.ID) { ret = info; break; } } // if there is no default account use the first one. if (ret == null && this._accSettings.Count > 0) { ret = this._accSettings[0]; } return(ret); }
// these code bellow was created to try to fix the message retrieve delay. //private MessageStore _storeRetrieved; //public delegate string DelegateRetrieveMessagesAsynch(string mailbox); //public MessageStore StoreRetrieved //{ // get { return this._storeRetrieved; } //} //public bool reload = false; #endregion /// <summary> /// Method for retrieve messages for a mailbox. /// </summary> /// <param name="mailbox">The mailbox.</param> public void RetrieveMessages(string mailbox) { //DelegateRetrieveMessagesAsynch delegateMessage = RetrieveMessagesAsynch; //delegateMessage.BeginInvoke(mailbox, null, null); BindingList <MailMessage> mailMessages = new SortableBindingList <MailMessage>(); AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { int messageCount = this.GetMessageCount(mailbox); if (accountInfo.MailAccountType == AccountType.POP3) { mailMessages = this._pop3Controller.RetrieveMessages(1, messageCount); } else if (accountInfo.MailAccountType == AccountType.IMAP) { mailMessages = this._imap4Controller.RetrieveMessages(mailbox, 1, messageCount); } if (this._store.Messages != null) { foreach (MailMessage mailMessage in mailMessages) { if (!this._store.Messages.Contains(mailMessage)) { this._store.Messages.Add(mailMessage); this._store.UnreadCount++; } } } else { this._store.Messages = mailMessages; this._store.UnreadCount = mailMessages.Count; } } this.SaveMailMessages(mailbox, this._store.Messages); }
/// <summary> /// Connect the imap4 client. /// </summary> /// <param name="accountInfo">The account information.</param> public void Connect(AccountSettings.AccountInfo accountInfo) { if (accountInfo != null && accountInfo.MailAccountType == AccountType.IMAP) { this._imap4Client = new Imap4Client(); int port = accountInfo.InPort; bool ssl = accountInfo.IncomingIsSSL; string serverName = accountInfo.IncomingServerName; string user = accountInfo.EmailAddress; string password = accountInfo.Password; bool useInPort = accountInfo.InPortEnabled; if (ssl) { if (useInPort) { this._imap4Client.ConnectSsl(serverName, port); } else { this._imap4Client.ConnectSsl(serverName); } } else { if (useInPort) { this._imap4Client.Connect(serverName, port); } else { this._imap4Client.Connect(serverName); } } this._imap4Client.Login(user, password); } }
/// <summary> /// Method used for send a message. /// </summary> /// <param name="accountInfo">The account information.</param> /// <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> /// <returns>The ActiveUp.Net.Mail.Message sent or null if the message was not sent.</returns> public ActiveUp.Net.Mail.Message SendMessage(AccountSettings.AccountInfo accountInfo, string recipient, string subject, string body, string[] attachments) { // We create the message object. ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message(); try { // We assign the sender email. message.From.Email = accountInfo.EmailAddress; string separator = ","; string[] recipients = recipient.Split(separator.ToCharArray()); foreach (string r in recipients) { // We assign the recipient email message.To.Add(r); } // We assign the subject message.Subject = subject; // We assign the body text message.BodyText.Text = body; // We assign the attachments. foreach (string attachment in attachments) { message.Attachments.Add(attachment, false); } int port = accountInfo.OutPort; bool ssl = accountInfo.OutgoingIsSSL; string serverName = accountInfo.OutgoingServerName; string password = accountInfo.Password; bool useOutPort = accountInfo.OutPortEnabled; SaslMechanism saslMechanism = SaslMechanism.Login; // TODO string user = accountInfo.LoginName; if (user == null || user.Equals(string.Empty)) { user = accountInfo.EmailAddress; } if (ssl) { if (useOutPort) { SmtpClient.SendSsl(message, serverName, port, user, password, saslMechanism); } else { SmtpClient.SendSsl(message, serverName, user, password, saslMechanism); } } else { if (useOutPort) { SmtpClient.Send(message, serverName, port, user, password, saslMechanism); } else { SmtpClient.Send(message, serverName, user, password, saslMechanism); } } } catch (Exception ex) { message = null; // TODO - Manipulate the exception properly. throw ex; } return(message); }
/// <summary> /// Default constructor. /// </summary> /// <param name="accountInfo">The default account information.</param> public Imap4Controller(AccountSettings.AccountInfo accountInfo) { this.Connect(accountInfo); }
/// <summary> /// Method for remove an account information. /// </summary> /// <param name="accountInfo">The account information object.</param> public void DeleteAccountInfo(AccountSettings.AccountInfo accountInfo) { this._accSettings.Remove(accountInfo); this.Connect(); }
/// <summary> /// Method for set the default account information. /// </summary> /// <param name="accountInfo">The account information object.</param> public void SetDefaultAccountInfo(AccountSettings.AccountInfo accountInfo) { this._clientSettings.DefaultAccountID = accountInfo.ID; this.Connect(); }
// Region for Account Settings methods. #region AccountSettings /// <summary> /// Method for add an account information. /// </summary> /// <param name="accountInfo">The account information object.</param> public void AddAccountInfo(AccountSettings.AccountInfo accountInfo) { this._accSettings.AddAccount(accountInfo); this.Connect(); }