/// <summary> /// Initialises a new instance of the Skycap.Data.AccountSettingsData class. /// </summary> /// <param name="accountName">The account name.</param> /// <param name="emailService">The email service.</param> /// <param name="emailServiceProvider">The email service provider.</param> /// <param name="displayName">The email display name.</param> /// <param name="emailAddress">The email address.</param> /// <param name="userName">The user name.</param> /// <param name="password">The email password.</param> /// <param name="incomingMailServer">The incoming mail server.</param> /// <param name="incomingMailServerPort">The incoming mail server port.</param> /// <param name="isIncomingMailServerSsl">A value indicating whether the incoming mail server uses ssl.</param> /// <param name="outgoingMailServer">The incoming mail server.</param> /// <param name="outgoingMailServerPort">The incoming mail server port.</param> /// <param name="isOutgoingMailServerSsl">A value indicating whether the incoming mail server uses ssl.</param> /// <param name="outgoingMailServerRequiresAuthentication">A value indicating whether the outgoing mail server requires authentication.</param> /// <param name="isSendAndReceiveUserNameAndPasswordSame">true if send and receive user name and password are the same.</param> /// <param name="sendUserName">The send email user name.</param> /// <param name="sendPassword">The send email password.</param> /// <param name="useAnEmailSignature">true if an email signature should be used; otherwise, false.</param> /// <param name="emailSignature">The email signature.</param> /// <param name="downloadNewEmail">The download new email options.</param> /// <param name="downloadEmailsFrom">The download emails from.</param> /// <param name="keepEmailCopiesOnServer">true, if emails should be kept on the server after download.</param> /// <param name="contentToSyncEmail">true, if email content should be synced; otherwise, false.</param> public AccountSettingsData(string accountName, EmailService emailService, EmailServiceProvider emailServiceProvider, string displayName, string emailAddress, string userName, string password, string incomingMailServer, ushort incomingMailServerPort, bool isIncomingMailServerSsl, string outgoingMailServer, ushort outgoingMailServerPort, bool isOutgoingMailServerSsl, bool outgoingMailServerRequiresAuthentication, bool isSendAndReceiveUserNameAndPasswordSame, string sendUserName, string sendPassword, bool useAnEmailSignature, string emailSignature, DownloadNewEmailOptions downloadNewEmail, DownloadEmailsFromOptions downloadEmailsFrom, bool keepEmailCopiesOnServer, bool contentToSyncEmail) : base() { // Initialise local variables ImageSource = string.Format("/Assets/{0}.png", emailServiceProvider.ToString()); AccountName = accountName; EmailService = emailService; EmailServiceProvider = emailServiceProvider; DisplayName = displayName; EmailAddress = emailAddress; UserName = (string.IsNullOrEmpty(userName) ? emailAddress : userName); Password = password; IncomingMailServer = incomingMailServer; IncomingMailServerPort = incomingMailServerPort; IsIncomingMailServerSsl = isIncomingMailServerSsl; OutgoingMailServer = outgoingMailServer; OutgoingMailServerPort = outgoingMailServerPort; IsOutgoingMailServerSsl = isOutgoingMailServerSsl; OutgoingMailServerRequiresAuthentication = outgoingMailServerRequiresAuthentication; IsSendAndReceiveUserNameAndPasswordSame = isSendAndReceiveUserNameAndPasswordSame; if (IsSendAndReceiveUserNameAndPasswordSame) { SendUserName = UserName; SendPassword = Password; } else { SendUserName = sendUserName; SendPassword = sendPassword; } UseAnEmailSignature = useAnEmailSignature; EmailSignature = emailSignature; DownloadNewEmail = downloadNewEmail; DownloadEmailsFrom = downloadEmailsFrom; KeepEmailCopiesOnServer = keepEmailCopiesOnServer; ContentToSyncEmail = contentToSyncEmail; }
/// <summary> /// Determines if the supplied connection info is valid. /// </summary> /// <param name="message">The validation message.</param> /// <param name="isManualConfiguration">true if manual configuration; otherwise, false.</param> /// <param name="accountName">The account name.</param> /// <param name="displayName">The display name.</param> /// <param name="emailAddress">The email address.</param> /// <param name="username">The user name.</param> /// <param name="password">The password.</param> /// <param name="incomingEmailServer">The incoming email server.</param> /// <param name="incomingEmailServerPort">The incoming email server port.</param> /// <param name="incomingEmailServerRequiresSsl">true, if the incoming email server requires ssl; otherwise, false.</param> /// <param name="outgoingEmailServer">The outgoing email server.</param> /// <param name="outgoingEmailServerPort">The outgoing email server port.</param> /// <param name="outgoingEmailServerRequiresSsl">true, if the outgoing email server requires ssl; otherwise, false.</param> /// <param name="outgoingMailServerRequiresAuthentication">true, if the outgoing email server requires authentication; otherwise false.</param> /// <param name="useTheSameUsernameAndPasswordToSendAndReceiveEmail">true, if the same username and password to send and receive email; otherwise false.</param> /// <param name="sendUsername">The smtp user name.</param> /// <param name="sendPassword">The smtp password.</param> /// <returns>true, if connection info is valid; otherwise, false.</returns> private bool IsConnectionInfoValid(out string message, out bool isManualConfiguration, out string accountName, out string displayName, out string emailAddress, out string username, out string password, out string incomingEmailServer, out ushort incomingEmailServerPort, out bool incomingEmailServerRequiresSsl, out string outgoingEmailServer, out ushort outgoingEmailServerPort, out bool outgoingEmailServerRequiresSsl, out bool outgoingMailServerRequiresAuthentication, out bool useTheSameUsernameAndPasswordToSendAndReceiveEmail, out string sendUsername, out string sendPassword) { // Default variables message = string.Empty; isManualConfiguration = (EmailServiceProvider == EmailServiceProvider.Other && hbShowMoreDetails.Visibility == Visibility.Collapsed); accountName = string.Empty; displayName = Task.Run(() => AccountSettingsData.GetDisplayName()).Result; emailAddress = txtEmailAddress.Text.Trim(); username = txtUsername.Text.Trim(); password = pbPassword.Password.Trim(); incomingEmailServer = txtIncomingEmailServer.Text.Trim(); incomingEmailServerPort = ushort.Parse(txtIncomingEmailServerPort.Text.Trim()); incomingEmailServerRequiresSsl = cbIncomingEmailServerRequiresSsl.IsChecked.Value; outgoingEmailServer = txtOutgoingEmailServer.Text.Trim(); outgoingEmailServerPort = ushort.Parse(txtOutgoingEmailServerPort.Text.Trim()); outgoingEmailServerRequiresSsl = cbOutgoingEmailServerRequiresSsl.IsChecked.Value; outgoingMailServerRequiresAuthentication = cbOutgoingMailServerRequiresAuthentication.IsChecked.Value; useTheSameUsernameAndPasswordToSendAndReceiveEmail = cbUseTheSameUsernameAndPasswordToSendAndReceiveEmail.IsChecked.Value; sendUsername = txtSendUsername.Text.Trim(); sendPassword = pbSendPassword.Password.Trim(); // Validate email address if (string.IsNullOrEmpty(emailAddress) || !Regex.IsMatch(emailAddress, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")) { txtEmailAddress.Focus(FocusState.Programmatic); message = "Please specify a valid email address."; return(false); } // Validate password else if (string.IsNullOrEmpty(password)) { pbPassword.Focus(FocusState.Programmatic); message = "Please specify the password."; return(false); } // Else if manual configuration else if (EmailServiceProvider == EmailServiceProvider.Other) { if (hbShowLessDetails.Visibility == Visibility.Visible) { // Validate incoming email server if (string.IsNullOrEmpty(incomingEmailServer)) { txtIncomingEmailServer.Focus(FocusState.Programmatic); message = "Please specify the incoming email server."; return(false); } // Validate incoming email server port else if (incomingEmailServerPort == 0) { txtIncomingEmailServerPort.Focus(FocusState.Programmatic); message = "Please specify the incoming email server port."; return(false); } // Validate outgoing email server else if (string.IsNullOrEmpty(outgoingEmailServer)) { txtOutgoingEmailServer.Focus(FocusState.Programmatic); message = "Please specify the outgoing email server."; return(false); } // Validate outgoing email server port else if (outgoingEmailServerPort == 0) { txtOutgoingEmailServerPort.Focus(FocusState.Programmatic); message = "Please specify the outgoing email server port."; return(false); } else if (!cbUseTheSameUsernameAndPasswordToSendAndReceiveEmail.IsChecked.Value) { // Validate smtp user name if (string.IsNullOrEmpty(sendUsername)) { txtSendUsername.Focus(FocusState.Programmatic); message = "Please specify the outgoing email server user name."; return(false); } // Validate smtp password else if (string.IsNullOrEmpty(sendPassword)) { pbSendPassword.Focus(FocusState.Programmatic); message = "Please specify the outgoing email server password."; return(false); } } } } // Set the account name if (EmailServiceProvider == EmailServiceProvider.Other) { string domainPart = emailAddress.Split('@')[1]; accountName = domainPart.Split('.')[0].ToWords(); } else { accountName = EmailServiceProvider.ToString(); } // If we reach this point, all connection info is valid return(true); }
/// <summary> /// Show popup on screen. /// </summary> public void Show() { // Dialog is open MainPage.Current.IsDialogOpen = true; // Hide show more or less hyperlink buttons by default hbShowMoreDetails.Visibility = Visibility.Collapsed; hbShowLessDetails.Visibility = Visibility.Collapsed; // Set default ports SetDefaultPorts(true, true); // Set title background SetTitleBackground(); // Set sub title and incoming server txtSubTitle.Text = string.Format("Complete the information below to connect to your {0} account", EmailServiceProvider.ToString()); tbIncomingEmailServer.Text = string.Format("Incoming ({0}) email server", EmailService.ToString().ToUpper()); // Set MailAccountDialog properties cdMailAccountDialog.Title = string.Format("Add your {0} account", EmailServiceProvider.ToString()); cdMailAccountDialog.TitleImageSource = new BitmapImage(new Uri(this.BaseUri, string.Format("/Assets/{0}.png", EmailServiceProvider.ToString()))); cdMailAccountDialog.IsOpen = true; }
/// <summary> /// Converts a value. /// </summary> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="language">The culture to use in the converter.</param> /// <returns>A converted value. If the method returns null, the valid null value is used.</returns> public object Convert(object value, Type targetType, object parameter, string language) { EmailServiceProvider emailServiceProvider = (EmailServiceProvider)value; return(emailServiceProvider.ToString()); }