public void AolStartTlsTest() { var profi_trol = new MailBox { Name = "", EMail = new MailAddress("*****@*****.**"), Account = "profi.troll", Password = "******", AuthenticationTypeIn = SaslMechanism.Login, IncomingEncryptionType = EncryptionType.StartTLS, Imap = true, Port = 143, Server = "imap.aol.com", SmtpAccount = "profi.troll", SmtpPassword = "******", AuthenticationTypeSmtp = SaslMechanism.Login, OutcomingEncryptionType = EncryptionType.StartTLS, SmtpPort = 587, SmtpServer = "smtp.aol.com" }; Assert.IsTrue(MailServerHelper.Test(profi_trol)); }
public int SetAccountEnable(string email, bool state) { if (string.IsNullOrEmpty(email)) { throw new ArgumentNullException("email"); } var mailbox = MailBoxManager.GetMailBox(TenantId, Username, new MailAddress(email)); if (mailbox == null) { throw new NullReferenceException(String.Format("Account wasn't founded by email: {0}", email)); } if (state) { // Check account connection setting on activation string errorText = null; try { MailServerHelper.Test(mailbox); } catch (ImapConnectionException exImap) { errorText = GetFormattedTextError(exImap, ServerType.Imap, exImap is ImapConnectionTimeoutException); } catch (Pop3ConnectionException exPop3) { errorText = GetFormattedTextError(exPop3, ServerType.Pop3, exPop3 is Pop3ConnectionTimeoutException); } catch (SmtpConnectionException exSmtp) { errorText = GetFormattedTextError(exSmtp, ServerType.Smtp, exSmtp is SmtpConnectionTimeoutException); } catch (Exception ex) { errorText = GetFormattedTextError(ex); } if (!string.IsNullOrEmpty(errorText)) { throw new AuthenticationException(errorText); } } if (!MailBoxManager.EnableMaibox(mailbox, state)) { throw new Exception("EnableMaibox failed."); } return(mailbox.MailBoxId); }
public static MailBox CreateAccount(MailBox mbox) { Logger.Info("Account: " + mbox.Account + "; Password: "******"Imap: " + mbox.Imap + "; Server: " + mbox.Server + "; Port: " + mbox.Port + "; AuthenticationType: " + mbox.AuthenticationTypeIn + "; EncryptionType: " + mbox.IncomingEncryptionType); Logger.Info("SmtpServer: " + mbox.SmtpServer + "; SmtpPort: " + mbox.SmtpPort + "; AuthenticationType: " + mbox.AuthenticationTypeSmtp + "; OutcomingEncryptionType: " + mbox.OutcomingEncryptionType); try { MailServerHelper.Test(mbox); return(mbox); } catch (ImapConnectionException ex_imap) { if (ex_imap is ImapConnectionTimeoutException) { Logger.Info("ImapConnectionTimeoutException: " + ex_imap.Message); } else { Logger.Info("ImapConnectionException: " + ex_imap.Message); } } catch (Pop3ConnectionException ex_pop) { if (ex_pop is Pop3ConnectionTimeoutException) { Logger.Info("Pop3ConnectionTimeoutException: " + ex_pop.Message); } else { Logger.Info("Pop3ConnectionException: " + ex_pop.Message); } } catch (SmtpConnectionException ex_smtp) { if (ex_smtp is SmtpConnectionTimeoutException) { Logger.Info("SmtpConnectionTimeoutException: " + ex_smtp.Message); } else { Logger.Info("SmtpConnectionException: " + ex_smtp.Message); } } catch (Exception ex) { Logger.Info("Exception: " + ex.Message); } throw new Exception(); }
public MailBox UpdateAccount(string name, string email, string account, string password, int port, string server, string smtp_account, string smtp_password, int smtp_port, string smtp_server, bool smtp_auth, bool restrict, EncryptionType incoming_encryption_type, EncryptionType outcoming_encryption_type, SaslMechanism auth_type_in, SaslMechanism auth_type_smtp) { if (string.IsNullOrEmpty(email)) { throw new ArgumentException(); } var mbox = MailBoxManager.GetMailBox(TenantId, Username, new MailAddress(email)); if (null == mbox) { throw new ArgumentException("Mailbox with specified email doesn't exist."); } if (mbox.IsTeamlab) { throw new ArgumentException("Mailbox with specified email can't be updated"); } if (string.IsNullOrEmpty(password)) { password = mbox.Password; } if (string.IsNullOrEmpty(smtp_password)) { smtp_password = mbox.SmtpPassword; } string error_text; mbox.Account = account; mbox.Name = name; mbox.Password = password; mbox.SmtpAccount = smtp_account; mbox.SmtpPassword = smtp_password; mbox.Port = port; mbox.Server = server; mbox.SmtpPort = smtp_port; mbox.SmtpServer = smtp_server; mbox.SmtpAuth = smtp_auth; mbox.Restrict = restrict; mbox.BeginDate = mbox.Restrict ? DateTime.Now.Subtract(new TimeSpan(mbox.MailLimitedTimeDelta)) : mbox.MailBeginTimestamp; mbox.IncomingEncryptionType = incoming_encryption_type; mbox.OutcomingEncryptionType = outcoming_encryption_type; mbox.AuthenticationTypeIn = auth_type_in; mbox.AuthenticationTypeSmtp = auth_type_smtp; mbox.InServerId = MailBoxManager.SaveMailServerSettings(mbox.EMail, new MailServerSettings { AccountName = mbox.Account, AccountPass = mbox.Password, AuthenticationType = mbox.AuthenticationTypeIn, EncryptionType = mbox.IncomingEncryptionType, Port = mbox.Port, Url = mbox.Server }, mbox.Imap ? "imap" : "pop3", AuthorizationServiceType.Unknown); mbox.SmtpServerId = MailBoxManager.SaveMailServerSettings(mbox.EMail, new MailServerSettings { AccountName = mbox.SmtpAccount, AccountPass = mbox.SmtpPassword, AuthenticationType = mbox.AuthenticationTypeSmtp, EncryptionType = mbox.OutcomingEncryptionType, Port = mbox.SmtpPort, Url = mbox.SmtpServer }, "smtp", AuthorizationServiceType.Unknown); try { if (!string.IsNullOrEmpty(mbox.RefreshToken) || MailServerHelper.Test(mbox)) { if (!MailBoxManager.SaveMailBox(mbox)) { throw new Exception("Failed to_addresses update account"); } } return(mbox); } catch (ImapConnectionException ex_imap) { error_text = GetFormattedTextError(ex_imap, ServerType.Imap, ex_imap is ImapConnectionTimeoutException); } catch (Pop3ConnectionException ex_pop3) { error_text = GetFormattedTextError(ex_pop3, ServerType.Pop3, ex_pop3 is Pop3ConnectionTimeoutException); } catch (SmtpConnectionException ex_smtp) { error_text = GetFormattedTextError(ex_smtp, ServerType.Smtp, ex_smtp is SmtpConnectionTimeoutException); } catch (Exception ex) { error_text = GetFormattedTextError(ex, mbox.Imap ? ServerType.Imap : ServerType.Pop3); } throw new Exception(error_text); }
public MailBox CreateAccount(string name, string email, string account, string password, int port, string server, string smtp_account, string smtp_password, int smtp_port, string smtp_server, bool smtp_auth, bool imap, bool restrict, EncryptionType incoming_encryption_type, EncryptionType outcoming_encryption_type, SaslMechanism auth_type_in, SaslMechanism auth_type_smtp) { string error_text = null; var mbox = new MailBox { Name = name, EMail = new MailAddress(email), Account = account, Password = password, Port = port, Server = server, SmtpAccount = smtp_account, SmtpPassword = smtp_password, SmtpPort = smtp_port, SmtpServer = smtp_server, SmtpAuth = smtp_auth, Imap = imap, Restrict = restrict, TenantId = TenantId, UserId = Username, BeginDate = restrict ? DateTime.Now.Subtract(new TimeSpan(MailBox.DefaultMailLimitedTimeDelta)) : new DateTime(MailBox.DefaultMailBeginTimestamp), IncomingEncryptionType = incoming_encryption_type, OutcomingEncryptionType = outcoming_encryption_type, AuthenticationTypeIn = auth_type_in, AuthenticationTypeSmtp = auth_type_smtp }; try { MailServerHelper.Test(mbox); } catch (ImapConnectionException ex_imap) { error_text = GetFormattedTextError(ex_imap, ServerType.Imap, ex_imap is ImapConnectionTimeoutException); } catch (Pop3ConnectionException ex_pop3) { error_text = GetFormattedTextError(ex_pop3, ServerType.Pop3, ex_pop3 is Pop3ConnectionTimeoutException); } catch (SmtpConnectionException ex_smtp) { error_text = GetFormattedTextError(ex_smtp, ServerType.Smtp, ex_smtp is SmtpConnectionTimeoutException); } catch (Exception ex) { error_text = GetFormattedTextError(ex); } if (!string.IsNullOrEmpty(error_text)) { throw new Exception(error_text); } try { mbox.InServerId = MailBoxManager.SaveMailServerSettings(mbox.EMail, new MailServerSettings { AccountName = mbox.Account, AccountPass = mbox.Password, AuthenticationType = mbox.AuthenticationTypeIn, EncryptionType = mbox.IncomingEncryptionType, Port = mbox.Port, Url = mbox.Server }, imap ? "imap" : "pop3", AuthorizationServiceType.Unknown); mbox.SmtpServerId = MailBoxManager.SaveMailServerSettings(mbox.EMail, new MailServerSettings { AccountName = mbox.SmtpAccount, AccountPass = mbox.SmtpPassword, AuthenticationType = mbox.AuthenticationTypeSmtp, EncryptionType = mbox.OutcomingEncryptionType, Port = mbox.SmtpPort, Url = mbox.SmtpServer }, "smtp", AuthorizationServiceType.Unknown); MailBoxManager.SaveMailBox(mbox); return(mbox); } catch (Exception ex) { //TODO: change AttachmentsUnknownError to common unknown error text error_text = GetFormattedTextError(ex, MailApiResource.AttachmentsUnknownError); } throw new Exception(error_text); }
private static MailBox CreateAccountSimple(string email, string password) { var begin_date = DateTime.Now.Subtract(new TimeSpan(MailBox.DefaultMailLimitedTimeDelta)); var mail_box_manager = new MailBoxManager(30); try { Logger.Info("Search mailbox settings:"); var mbox = mail_box_manager.SearchMailboxSettings(email, password, "", 0); Logger.Info("Account: " + mbox.Account + "; Password: "******"Imap: " + mbox.Imap + "; Server: " + mbox.Server + "; Port: " + mbox.Port + "; AuthenticationType: " + mbox.AuthenticationTypeIn + "; EncryptionType: " + mbox.IncomingEncryptionType); Logger.Info("SmtpServer: " + mbox.SmtpServer + "; SmtpPort: " + mbox.SmtpPort + "; AuthenticationType: " + mbox.AuthenticationTypeSmtp + "; OutcomingEncryptionType: " + mbox.OutcomingEncryptionType); mbox.BeginDate = begin_date; // Apply restrict for download MailServerHelper.Test(mbox); return(mbox); } catch (ImapConnectionException ex_imap) { if (ex_imap is ImapConnectionTimeoutException) { Logger.Info("ImapConnectionTimeoutException: " + ex_imap.Message); } else { Logger.Info("ImapConnectionException: " + ex_imap.Message); } } catch (Pop3ConnectionException ex_pop) { if (ex_pop is Pop3ConnectionTimeoutException) { Logger.Info("Pop3ConnectionTimeoutException: " + ex_pop.Message); } else { Logger.Info("Pop3ConnectionException: " + ex_pop.Message); } } catch (SmtpConnectionException ex_smtp) { if (ex_smtp is SmtpConnectionTimeoutException) { Logger.Info("SmtpConnectionTimeoutException: " + ex_smtp.Message); } else { Logger.Info("SmtpConnectionException: " + ex_smtp.Message); } } catch (Exception ex) { Logger.Info("Exception: " + ex.Message); } throw new Exception(); }
public MailBox CreateAccountSimple(string email, string password) { if (string.IsNullOrEmpty(email)) { throw new ArgumentException("Empty email", "email"); } var begin_date = DateTime.Now.Subtract(new TimeSpan(MailBox.DefaultMailLimitedTimeDelta)); string error_text; try { var mbox = MailBoxManager.SearchMailboxSettings(email, password, Username, TenantId); mbox.BeginDate = begin_date; // Apply restrict for download MailServerHelper.Test(mbox); mbox.InServerId = MailBoxManager.SaveMailServerSettings(mbox.EMail, new MailServerSettings { AccountName = mbox.Account, AccountPass = mbox.Password, AuthenticationType = mbox.AuthenticationTypeIn, EncryptionType = mbox.IncomingEncryptionType, Port = mbox.Port, Url = mbox.Server }, mbox.Imap ? "imap" : "pop3", AuthorizationServiceType.Unknown); mbox.SmtpServerId = MailBoxManager.SaveMailServerSettings(mbox.EMail, new MailServerSettings { AccountName = mbox.SmtpAccount, AccountPass = mbox.SmtpPassword, AuthenticationType = mbox.AuthenticationTypeSmtp, EncryptionType = mbox.OutcomingEncryptionType, Port = mbox.SmtpPort, Url = mbox.SmtpServer }, "smtp", AuthorizationServiceType.Unknown); MailBoxManager.SaveMailBox(mbox); return(mbox); } catch (ImapConnectionException ex_imap) { error_text = GetFormattedTextError(ex_imap, ServerType.Imap, ex_imap is ImapConnectionTimeoutException); } catch (Pop3ConnectionException ex_pop) { error_text = GetFormattedTextError(ex_pop, ServerType.Pop3, ex_pop is Pop3ConnectionTimeoutException); } catch (SmtpConnectionException ex_smtp) { error_text = GetFormattedTextError(ex_smtp, ServerType.Smtp, ex_smtp is SmtpConnectionTimeoutException); } catch (Exception ex) { error_text = GetFormattedTextError(ex, ServerType.Imap); } throw new Exception(string.Format("{0}", error_text)); }