/// <summary> /// Method for connect the imcoming mail, Pop or Imap. /// </summary> public void Connect() { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { if (accountInfo.IncomingMailServer == Constants.POP3) { if (popController.Pop3Client == null || !popController.Pop3Client.IsConnected) { this.popController.Connect(accountInfo); } else { this.Disconnect(); this.popController.Connect(accountInfo); } } else { if (_imapController.Imap4Client == null || !_imapController.Imap4Client.IsConnected) { this._imapController.Connect(accountInfo); } else { this.Disconnect(); this._imapController.Connect(accountInfo); } } } }
/// <summary> /// Method for loads account settings /// </summary> private void loadAccontSettings() { AccountSettings.AccountInfo acc_info = Facade.GetInstance().GetDefaultAccountInfo(); if (acc_info != null) { TextBoxPassword.Text = EncryptDescript.CriptDescript(acc_info.Password); TextBoxDisplayName.Text = acc_info.DisplayName; int i = 0; foreach (ListItem item in DropDownListIncomingServer.Items) { if (item.Text == acc_info.IncomingMailServer) { DropDownListIncomingServer.SelectedIndex = i; } i++; } TextBoxEmailAddress.Text = EncryptDescript.CriptDescript(acc_info.EmailAddress); TextBoxOutgoingServer.Text = acc_info.OutgoingServer; TextBoxLoginID.Text = acc_info.LoginId; TextBoxPortIncoming.Text = acc_info.PortIncomingServer.ToString(); TextBoxPortOutgoing.Text = acc_info.PortOutgoingServer.ToString(); CheckBoxSecureConnection.Checked = acc_info.IsIncomeSecureConnection; CheckBoxOutgoingSecure.Checked = acc_info.IsOutgoingSecureConnection; CheckBoxOutgoingAuthentication.Checked = acc_info.IsOutgoingWithAuthentication; CheckBoxPortIncoming.Checked = acc_info.PortIncomingChecked; CheckBoxPortOutgoing.Checked = acc_info.PortOutgoingChecked; TextBoxIncomingServer.Text = acc_info.IncomingNameMailServer; } }
private bool ImcomingWasChanged(int portIncomingServer) { AccountSettings.AccountInfo acc_info = Facade.GetInstance().GetDefaultAccountInfo(); if (acc_info == null) { return(true); } return(acc_info.PortIncomingServer != portIncomingServer); }
/// <summary> /// Method for sets an Account Information. /// </summary> /// <param name="acc">The Account information</param> public void setAccountInfo(AccountSettings.AccountInfo acc) { if (this._accSettings != null) { this._accSettings.Acc_Info = acc; } else { this.AccSettings = new AccountSettings(); this.AccSettings.Acc_Info = acc; } }
/// <summary> /// Method for gets all Messages. /// </summary> /// <returns>A List of Message</returns> public List <Message> getListMessages() { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (Constants.POP3 == accountInfo.IncomingMailServer) { return(this.popController.ListMessageInbox1); } else { return(this._imapController.ListMessageInbox); } }
/// <summary> /// Method for gets a message through its location index. /// </summary> /// <param name="index">The index</param> /// <returns>A message</returns> public Message getMessageByIndex(int index) { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo.IncomingMailServer == Constants.POP3) { return(this.popController.getMessageByIndex(index)); } else { return(this._imapController.getMessageByIndex(index)); } }
/// <summary> /// Method for gets all Headers message. /// </summary> /// <returns>A list of headers</returns> public object getListHeaders() { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (Constants.POP3 == accountInfo.IncomingMailServer) { return(this.popController.ListHeaderInbox); } else { return(this._imapController.ListHeaderInbox); } }
/// <summary> /// Method used for send a message. /// </summary> /// <param name="message">The message will be send.</param> /// <param name="acc">The account information.</param> public void SendMail(Message message, AccountSettings acc) { AccountSettings.AccountInfo arrayAcc_info = acc.Acc_Info; try { if (arrayAcc_info != null) { message.From.Email = arrayAcc_info.EmailAddress; string outgoing = arrayAcc_info.OutgoingServer; int smtp_Port = arrayAcc_info.PortOutgoingServer; string email = EncryptDescript.CriptDescript(arrayAcc_info.EmailAddress); string password = EncryptDescript.CriptDescript(arrayAcc_info.Password); bool ssl = arrayAcc_info.IsOutgoingSecureConnection; bool port = arrayAcc_info.PortOutgoingChecked; if (ssl) { if (port) { ActiveUp.Net.Mail.SmtpClient.SendSsl(message, outgoing, smtp_Port, email, password, ActiveUp.Net.Mail.SaslMechanism.Login); } else { ActiveUp.Net.Mail.SmtpClient.SendSsl(message, outgoing, email, password, ActiveUp.Net.Mail.SaslMechanism.Login); } } else { if (port) { ActiveUp.Net.Mail.SmtpClient.Send(message, outgoing, smtp_Port, email, password, ActiveUp.Net.Mail.SaslMechanism.Login); } else { ActiveUp.Net.Mail.SmtpClient.SendSsl(message, outgoing, email, password, ActiveUp.Net.Mail.SaslMechanism.Login); } } this.storeMessageSent(message); } } catch (Exception) { } }
/// <summary> ///Method for disconnect the imcoming mail, Pop or Imap. /// </summary> public void Disconnect() { AccountSettings.AccountInfo accountInfo = this.GetDefaultAccountInfo(); if (accountInfo != null) { if (accountInfo.IncomingMailServer == Constants.POP3 && (this.popController.Pop3Client != null && this.popController.Pop3Client.IsConnected)) { this.popController.Disconnect(); } else if (this._imapController.Imap4Client != null && this._imapController.Imap4Client.IsConnected) { this._imapController.Disconnect(); } } }
/// <summary> /// Connect the imap client. /// </summary> /// <param name="accountInfo">The information account</param> public void Connect(AccountSettings.AccountInfo accountInfo) { if (this._imap4Client == null || !this._imap4Client.IsConnected) { if (accountInfo != null && accountInfo.AccType == AccountType.POP3) { this._imap4Client = new Imap4Client(); int port = accountInfo.PortIncomingServer; bool ssl = accountInfo.IsIncomeSecureConnection; string serverName = accountInfo.IncomingNameMailServer; string user = accountInfo.EmailAddress; string password = accountInfo.Password; bool useInPort = accountInfo.PortIncomingChecked; 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); } } }
private void loadAccontSettings() { this.acc = AccountSettings.Load("AccountSettings"); //AccountSettings.AccountInfo acc_info = (AccountSettings.AccountInfo)((IEnumerator)this.acc.Accounts.GetEnumerator()).Current; AccountSettings.AccountInfo [] arrayAcc_info = this.acc.Accounts; if (arrayAcc_info != null) { AccountSettings.AccountInfo acc_info = arrayAcc_info[0]; if (acc_info != null) { TextBoxPassword.Text = acc_info.Password; TextBoxDisplayName.Text = acc_info.DisplayName; int i = 0; foreach (ListItem item in DropDownListIncomingServer.Items) { if (item.Text == acc_info.IncomingMailServer) { DropDownListIncomingServer.SelectedIndex = i; } i++; } TextBoxEmailAddress.Text = acc_info.EmailAddress; TextBoxOutgoingServer.Text = acc_info.OutgoingServer; TextBoxLoginID.Text = acc_info.LoginId; TextBoxPortIncoming.Text = acc_info.PortIncomingServer.ToString(); TextBoxPortOutgoing.Text = acc_info.PortOutgoingServer.ToString(); CheckBoxSecureConnection.Checked = acc_info.IsIncomeSecureConnection; CheckBoxOutgoingSecure.Checked = acc_info.IsOutgoingSecureConnection; CheckBoxOutgoingAuthentication.Checked = acc_info.IsOutgoingWithAuthentication; CheckBoxPortIncoming.Checked = acc_info.PortIncomingChecked; CheckBoxPortOutgoing.Checked = acc_info.PortOutgoingChecked; } } }
public Pop3Controller(AccountSettings.AccountInfo accountInfo) { //this.Connect(accountInfo); this.ListMessageInbox = new List <Message>(); this.ListHeaderInbox = new List <MailHeader>(); }
protected void ButtonOK_Action(object sender, EventArgs e) { string emailAddress; string password; string displayName; string incomingMailServer; string outgoingServer; string loginId; int portIncomingServer = 80; int portOutgoingServer = 80; bool isIncomeSecureConnection; bool isOutgoingSecureConnection; bool isOutgoingWithAuthentication; ErrorEmailAddress.Text = ""; ErrorPassword.Text = ""; ErrorDispName.Text = ""; if (TextBoxEmailAddress.Text.Equals(string.Empty) || !TextBoxEmailAddress.Text.Contains("@")) { ErrorEmailAddress.Text = "Enter a valid email address!"; } if (TextBoxPassword.Text.Equals(string.Empty)) { ErrorPassword.Text = "Enter a valid password!"; } if (TextBoxDisplayName.Text.Equals(string.Empty)) { ErrorDispName.Text = "Enter a valid display name!"; } emailAddress = TextBoxEmailAddress.Text; password = TextBoxPassword.Text; displayName = TextBoxDisplayName.Text; incomingMailServer = DropDownListIncomingServer.SelectedValue; if (CheckBoxPortIncoming.Checked) { if (!TextBoxPortIncoming.Text.Equals(string.Empty)) { portIncomingServer = Convert.ToInt32(TextBoxPortIncoming.Text); } } if (CheckBoxPortOutgoing.Checked) { if (!TextBoxPortOutgoing.Text.Equals(string.Empty)) { portOutgoingServer = Convert.ToInt32(TextBoxPortOutgoing.Text); } } isIncomeSecureConnection = CheckBoxSecureConnection.Checked; isOutgoingSecureConnection = CheckBoxOutgoingSecure.Checked; isOutgoingWithAuthentication = CheckBoxOutgoingAuthentication.Checked; loginId = TextBoxLoginID.Text; outgoingServer = TextBoxOutgoingServer.Text; //These informations are going to save AccountSettings.AccountInfo acc_info = new AccountSettings.AccountInfo(); acc_info.EmailAddress = emailAddress; acc_info.Password = password; acc_info.DisplayName = displayName; acc_info.IncomingMailServer = incomingMailServer; acc_info.OutgoingServer = outgoingServer; acc_info.LoginId = loginId; acc_info.PortIncomingServer = portIncomingServer; acc_info.PortOutgoingServer = portOutgoingServer; acc_info.IsIncomeSecureConnection = isIncomeSecureConnection; acc_info.IsOutgoingSecureConnection = isOutgoingSecureConnection; acc_info.IsOutgoingWithAuthentication = isOutgoingWithAuthentication; acc_info.PortIncomingChecked = CheckBoxPortIncoming.Checked; acc_info.PortOutgoingChecked = CheckBoxPortOutgoing.Checked; this.acc.Add(acc_info); AccountSettings.Save("AccountSettings", acc); }
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> /// Event for confirms the settings displayed in the page /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">The event arguments</param> protected void ButtonOK_Click(object sender, EventArgs e) { string emailAddress; string password; string displayName; string incomingMailServer; string outgoingServer; string loginId; string incomingNameMailServer; int portIncomingServer = 0; int portOutgoingServer = 0; bool isIncomeSecureConnection; bool isOutgoingSecureConnection; bool isOutgoingWithAuthentication; emailAddress = TextBoxEmailAddress.Text; password = TextBoxPassword.Text; displayName = TextBoxDisplayName.Text; incomingNameMailServer = TextBoxIncomingServer.Text; incomingMailServer = DropDownListIncomingServer.SelectedValue; try { if (CheckBoxPortIncoming.Checked) { if (!TextBoxPortIncoming.Text.Equals(string.Empty)) { portIncomingServer = Convert.ToInt32(TextBoxPortIncoming.Text); if (this.ImcomingWasChanged(portIncomingServer)) { Facade.GetInstance().ChangeImcoming = true; } } } if (CheckBoxPortOutgoing.Checked) { if (!TextBoxPortOutgoing.Text.Equals(string.Empty)) { portOutgoingServer = Convert.ToInt32(TextBoxPortOutgoing.Text); } } } catch (Exception) { Session["ErrorMessage"] = "The port must be an integer"; Response.Redirect("~/ErrorPage.aspx"); } isIncomeSecureConnection = CheckBoxSecureConnection.Checked; isOutgoingSecureConnection = CheckBoxOutgoingSecure.Checked; isOutgoingWithAuthentication = CheckBoxOutgoingAuthentication.Checked; loginId = TextBoxLoginID.Text; outgoingServer = TextBoxOutgoingServer.Text; //These informations are going to save AccountSettings.AccountInfo acc_info = new AccountSettings.AccountInfo(); acc_info.EmailAddress = EncryptDescript.CriptDescript(emailAddress); acc_info.Password = EncryptDescript.CriptDescript(password); acc_info.DisplayName = displayName; acc_info.IncomingMailServer = incomingMailServer; acc_info.OutgoingServer = outgoingServer; acc_info.LoginId = loginId; acc_info.PortIncomingServer = portIncomingServer; acc_info.PortOutgoingServer = portOutgoingServer; acc_info.IncomingNameMailServer = incomingNameMailServer; acc_info.IsIncomeSecureConnection = isIncomeSecureConnection; acc_info.IsOutgoingSecureConnection = isOutgoingSecureConnection; acc_info.IsOutgoingWithAuthentication = isOutgoingWithAuthentication; acc_info.PortIncomingChecked = CheckBoxPortIncoming.Checked; acc_info.PortOutgoingChecked = CheckBoxPortOutgoing.Checked; Facade f = Facade.GetInstance(); f.setAccountInfo(acc_info); f.SaveAccountSettings(); try { f.Disconnect(); } catch (Exception) { Facade.GetInstance().deleteAccountSettings(); Session["ErrorMessage"] = "Could not be disconnected with imcoming server"; Response.Redirect("~/ErrorPage.aspx"); } try { f.Connect(); } catch (Exception) { Facade.GetInstance().deleteAccountSettings(); Session["ErrorMessage"] = "Could not be connected with imcoming server, review the account settings"; //how the settings is not valid set null Facade.GetInstance().AccSettings = null; Response.Redirect("~/ErrorPage.aspx"); } Session["SucessMessage"] = "Account Settings updated with success!"; Response.Redirect("~/SucessPage.aspx"); }
/// <summary> /// Event for confirms the settings displayed in the page /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">The event arguments</param> protected void ButtonOK_Click(object sender, EventArgs e) { string emailAddress; string password; string displayName; string incomingMailServer; string outgoingServer; string loginId; string incomingNameMailServer; int portIncomingServer = 0; int portOutgoingServer = 0; bool isIncomeSecureConnection; bool isOutgoingSecureConnection; bool isOutgoingWithAuthentication; emailAddress = TextBoxEmailAddress.Text; password = TextBoxPassword.Text; displayName = TextBoxDisplayName.Text; incomingNameMailServer = TextBoxIncomingServer.Text; incomingMailServer = DropDownListIncomingServer.SelectedValue; try { if (CheckBoxPortIncoming.Checked) { if (!TextBoxPortIncoming.Text.Equals(string.Empty)) { portIncomingServer = Convert.ToInt32(TextBoxPortIncoming.Text); if (this.ImcomingWasChanged(portIncomingServer)) Facade.GetInstance().ChangeImcoming = true; } } if (CheckBoxPortOutgoing.Checked) { if (!TextBoxPortOutgoing.Text.Equals(string.Empty)) { portOutgoingServer = Convert.ToInt32(TextBoxPortOutgoing.Text); } } } catch (Exception) { Session["ErrorMessage"] = "The port must be an integer"; Response.Redirect("~/ErrorPage.aspx"); } isIncomeSecureConnection = CheckBoxSecureConnection.Checked; isOutgoingSecureConnection = CheckBoxOutgoingSecure.Checked; isOutgoingWithAuthentication = CheckBoxOutgoingAuthentication.Checked; loginId = TextBoxLoginID.Text; outgoingServer = TextBoxOutgoingServer.Text; //These informations are going to save AccountSettings.AccountInfo acc_info = new AccountSettings.AccountInfo(); acc_info.EmailAddress = EncryptDescript.CriptDescript(emailAddress); acc_info.Password = EncryptDescript.CriptDescript(password); acc_info.DisplayName = displayName; acc_info.IncomingMailServer = incomingMailServer; acc_info.OutgoingServer = outgoingServer; acc_info.LoginId = loginId; acc_info.PortIncomingServer = portIncomingServer; acc_info.PortOutgoingServer = portOutgoingServer; acc_info.IncomingNameMailServer = incomingNameMailServer; acc_info.IsIncomeSecureConnection = isIncomeSecureConnection; acc_info.IsOutgoingSecureConnection = isOutgoingSecureConnection; acc_info.IsOutgoingWithAuthentication = isOutgoingWithAuthentication; acc_info.PortIncomingChecked = CheckBoxPortIncoming.Checked; acc_info.PortOutgoingChecked = CheckBoxPortOutgoing.Checked; Facade f = Facade.GetInstance(); f.setAccountInfo(acc_info); f.SaveAccountSettings(); try { f.Disconnect(); } catch (Exception) { Facade.GetInstance().deleteAccountSettings(); Session["ErrorMessage"] = "Could not be disconnected with imcoming server"; Response.Redirect("~/ErrorPage.aspx"); } try { f.Connect(); } catch(Exception) { Facade.GetInstance().deleteAccountSettings(); Session["ErrorMessage"] = "Could not be connected with imcoming server, review the account settings"; //how the settings is not valid set null Facade.GetInstance().AccSettings = null; Response.Redirect("~/ErrorPage.aspx"); } Session["SucessMessage"] = "Account Settings updated with success!"; Response.Redirect("~/SucessPage.aspx"); }
protected void ButtonOK_Action(object sender, EventArgs e) { string emailAddress; string password; string displayName; string incomingMailServer; string outgoingServer; string loginId; int portIncomingServer = 80; int portOutgoingServer = 80; bool isIncomeSecureConnection; bool isOutgoingSecureConnection; bool isOutgoingWithAuthentication; ErrorEmailAddress.Text = ""; ErrorPassword.Text = ""; ErrorDispName.Text = ""; if (TextBoxEmailAddress.Text.Equals(string.Empty) || !TextBoxEmailAddress.Text.Contains("@")) { ErrorEmailAddress.Text = "Enter a valid email address!"; } if (TextBoxPassword.Text.Equals(string.Empty)) { ErrorPassword.Text = "Enter a valid password!"; } if (TextBoxDisplayName.Text.Equals(string.Empty)) { ErrorDispName.Text = "Enter a valid display name!"; } emailAddress = TextBoxEmailAddress.Text; password = TextBoxPassword.Text; displayName = TextBoxDisplayName.Text; incomingMailServer = DropDownListIncomingServer.SelectedValue; if (CheckBoxPortIncoming.Checked) { if (!TextBoxPortIncoming.Text.Equals(string.Empty)) { portIncomingServer = Convert.ToInt32(TextBoxPortIncoming.Text); } } if (CheckBoxPortOutgoing.Checked) { if (!TextBoxPortOutgoing.Text.Equals(string.Empty)) { portOutgoingServer = Convert.ToInt32(TextBoxPortOutgoing.Text); } } isIncomeSecureConnection = CheckBoxSecureConnection.Checked; isOutgoingSecureConnection = CheckBoxOutgoingSecure.Checked; isOutgoingWithAuthentication = CheckBoxOutgoingAuthentication.Checked; loginId = TextBoxLoginID.Text; outgoingServer = TextBoxOutgoingServer.Text; //These informations are going to save AccountSettings.AccountInfo acc_info = new AccountSettings.AccountInfo(); acc_info.EmailAddress = emailAddress; acc_info.Password = password; acc_info.DisplayName = displayName; acc_info.IncomingMailServer = incomingMailServer; acc_info.OutgoingServer = outgoingServer; acc_info.LoginId = loginId; acc_info.PortIncomingServer = portIncomingServer; acc_info.PortOutgoingServer = portOutgoingServer; acc_info.IsIncomeSecureConnection = isIncomeSecureConnection; acc_info.IsOutgoingSecureConnection = isOutgoingSecureConnection; acc_info.IsOutgoingWithAuthentication = isOutgoingWithAuthentication; acc_info.PortIncomingChecked = CheckBoxPortIncoming.Checked; acc_info.PortOutgoingChecked = CheckBoxPortOutgoing.Checked; this.acc.Add(acc_info); AccountSettings.Save("AccountSettings",acc); }