// specifiy the connection settings private void SetConnectionSettingsFromForm(ref ConnectionSettings oConnectionSetting) { oConnectionSetting.User = this.txtBoxEmailAddress.Text; oConnectionSetting.Domain = this.txtBoxDomain.Text; oConnectionSetting.UseSSL = this.chkEnableSSL.Checked; oConnectionSetting.PasswordRequired = this.chkPasswordRequired.Checked; oConnectionSetting.MessageTo = this.txtBoxTo.Text; oConnectionSetting.MessageCC = this.txtBoxCC.Text; oConnectionSetting.MessageBcc = this.txtBoxBCC.Text; oConnectionSetting.MessageSubject = this.txtBoxSubject.Text; oConnectionSetting.MessageBody = this.richTxtBody.Text; oConnectionSetting.Port = this.cboPort.Text; oConnectionSetting.Server = this.cboServer.Text; oConnectionSetting.SendByPort = this.rdoSendByPort.Checked; oConnectionSetting.CustomPickupLocation = this.chkBoxSpecificPickupFolder.Checked; oConnectionSetting.PickupLocation = this.txtPickupFolder.Text; }
// apply settings for the form private void SetFormFromConnectionSettings(ConnectionSettings oConnectionSetting) { try { this.txtBoxEmailAddress.Text = FixSetting(oConnectionSetting.User); this.txtBoxDomain.Text = FixSetting(oConnectionSetting.Domain); this.txtBoxSubject.Text = FixSetting(oConnectionSetting.MessageSubject); this.txtBoxTo.Text = FixSetting(oConnectionSetting.MessageTo); this.txtBoxCC.Text = FixSetting(oConnectionSetting.MessageCC); this.txtBoxBCC.Text = FixSetting(oConnectionSetting.MessageBcc); this.richTxtBody.Text = FixSetting(oConnectionSetting.MessageBody); if (oConnectionSetting.SendByPort == true) { this.rdoSendByPort.Checked = true; this.cboPort.Text = oConnectionSetting.Port; this.cboServer.Text = oConnectionSetting.Server; } else { this.rdoSendByPickupFolder.Checked = true; this.chkBoxSpecificPickupFolder.Checked = oConnectionSetting.CustomPickupLocation; this.txtPickupFolder.Text = FixSetting(oConnectionSetting.PickupLocation); } } catch (Exception ex) { txtBoxErrorLog.Clear(); txtBoxErrorLog.Text = ex.Message + "Error loading settings into form"; } }
/// <summary> /// save the current form settings to an xml file /// useriohelper is for displaying the save dialog /// setconnectionsettingsfromform handles which settings need to be saved /// then serialhelper streams that information to the file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuFileSaveSettings_Click(object sender, EventArgs e) { string sFile = string.Empty; string sFilter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; string sConnectionSettings = string.Empty; ConnectionSettings oConnectionSetting = new ConnectionSettings(); SetConnectionSettingsFromForm(ref oConnectionSetting); if (UserIoHelper.PickSaveFileToFolder(AppDomain.CurrentDomain.BaseDirectory, "Email Settings.xml", ref sFile, sFilter)) { sConnectionSettings = SerialHelper.SerializeObjectToString<ConnectionSettings>(oConnectionSetting); if (sConnectionSettings != string.Empty) { try { System.IO.File.WriteAllText(sFile, sConnectionSettings); } catch (Exception ex) { txtBoxErrorLog.Clear(); txtBoxErrorLog.Text = ex.Message + "Error Saving File"; } } } }