public bool CreateBPMOnlineFolder(Guid id, string userName, string userPassword) { if (UserConnection.GetIsFeatureEnabled("EmailIntegrationV2")) { return(false); } var currentMailServer = new MailServer(UserConnection); if (!currentMailServer.FetchFromDB(id)) { return(false); } var imapServerCredentials = new MailCredentials { Host = currentMailServer.GetTypedColumnValue <string>("Address"), Port = currentMailServer.GetTypedColumnValue <int>("Port"), UseSsl = currentMailServer.GetTypedColumnValue <bool>("UseSSL"), StartTls = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"), UserName = userName, UserPassword = userPassword }; var imapClient = ClassFactory.Get <IImapClient>("OldEmailIntegration", new ConstructorArgument("credentials", imapServerCredentials), new ConstructorArgument("errorMessages", new Terrasoft.Mail.ImapErrorMessages()), new ConstructorArgument("userConnection", UserConnection)); imapClient.EnsureFolderExists("BPMonline"); var mailboxFolderTypeId = new Guid("99c2351c-f0f8-e111-9dba-00155d051801"); var emailFolderTypeId = new Guid("b97a5836-1cd0-e111-90c6-00155d054c03"); var mailboxFolder = new ActivityFolder(UserConnection); if (mailboxFolder.FetchFromDB( new Dictionary <string, object> { { "FolderType", mailboxFolderTypeId }, { "Name", imapServerCredentials.UserName } })) { var activityFolderSchema = UserConnection.EntitySchemaManager.GetInstanceByName("ActivityFolder"); var bpmonlineFolder = activityFolderSchema.CreateEntity(UserConnection); var parentColumn = activityFolderSchema.Columns.GetByName("Parent"); var folderTypeColumn = activityFolderSchema.Columns.GetByName("FolderType"); bpmonlineFolder.SetDefColumnValues(); bpmonlineFolder.SetColumnValue("Name", "BPMonline"); bpmonlineFolder.SetColumnValue(parentColumn.ColumnValueName, mailboxFolder.PrimaryColumnValue); bpmonlineFolder.SetColumnValue(folderTypeColumn.ColumnValueName, emailFolderTypeId); bpmonlineFolder.Save(); return(true); } return(false); }
public IsValidAnswer IsServerValid(Guid id, string userName, string userPassword, bool enableSync, bool sendEmail, string senderEmailAddress, bool isAnonymousAuthentication) { var currentMailServer = new MailServer(UserConnection); var isValidAnswer = new IsValidAnswer() { IsValid = true, Message = string.Empty }; if (!currentMailServer.FetchFromDB(id)) { isValidAnswer.IsValid = false; return(isValidAnswer); } if (currentMailServer.AllowEmailDownloading && enableSync) { try { var imapServerCredentials = new MailCredentials { Host = currentMailServer.Address, Port = currentMailServer.Port, UseSsl = currentMailServer.UseSSL, StartTls = currentMailServer.IsStartTls, UserName = userName, UserPassword = userPassword }; var mapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true); } catch (ImapException exception) { isValidAnswer.IsValid = false; isValidAnswer.Message = ConnectToImapServerCaption.ToString() + exception.Message; } } if (currentMailServer.AllowEmailSending && sendEmail) { var smtpServerCredentials = new MailCredentials(); if (isAnonymousAuthentication) { smtpServerCredentials.IsAnonymousAuthentication = true; } else { smtpServerCredentials.UserName = userName; smtpServerCredentials.UserPassword = userPassword; } smtpServerCredentials.Host = currentMailServer.SMTPServerAddress; smtpServerCredentials.Port = currentMailServer.SMTPPort; smtpServerCredentials.UseSsl = currentMailServer.UseSSLforSending; smtpServerCredentials.StartTls = currentMailServer.IsStartTls; smtpServerCredentials.Timeout = currentMailServer.SMTPServerTimeout * 1000; smtpServerCredentials.SenderEmailAddress = senderEmailAddress; var smtpClient = new SmtpClient(UserConnection, smtpServerCredentials); try { smtpClient.SendTestMessage(); } catch (SmtpException ex) { if (!string.IsNullOrEmpty(isValidAnswer.Message)) { isValidAnswer.Message += Environment.NewLine; } isValidAnswer.IsValid = false; isValidAnswer.Message += CanNotSendTestMessageCaption.ToString() + ex.Message; } } return(isValidAnswer); }
public IsValidAnswer IsServerValid(Guid id, string userName, string userPassword, bool enableSync, bool sendEmail, string senderEmailAddress, bool isAnonymousAuthentication) { var currentMailServer = new MailServer(UserConnection); var isValidAnswer = new IsValidAnswer() { IsValid = true, Message = string.Empty }; if (!currentMailServer.FetchFromDB(id)) { isValidAnswer.IsValid = false; return(isValidAnswer); } if (currentMailServer.AllowEmailDownloading && enableSync) { try { var imapServerCredentials = new MailCredentials { Host = currentMailServer.Address, Port = currentMailServer.Port, UseSsl = currentMailServer.UseSSL, StartTls = currentMailServer.IsStartTls, UserName = userName, UserPassword = userPassword }; var imapClient = ClassFactory.Get <IImapClient>("OldEmailIntegration", new ConstructorArgument("credentials", imapServerCredentials), new ConstructorArgument("errorMessages", new Terrasoft.Mail.ImapErrorMessages()), new ConstructorArgument("userConnection", UserConnection), new ConstructorArgument("login", true)); } catch (ImapException exception) { isValidAnswer.IsValid = false; isValidAnswer.Message = ConnectToImapServerCaption.ToString() + exception.Message; } } if (currentMailServer.AllowEmailSending && sendEmail) { var smtpServerCredentials = new MailCredentials(); if (isAnonymousAuthentication) { smtpServerCredentials.IsAnonymousAuthentication = true; } else { smtpServerCredentials.UserName = userName; smtpServerCredentials.UserPassword = userPassword; } smtpServerCredentials.Host = currentMailServer.SMTPServerAddress; smtpServerCredentials.Port = currentMailServer.SMTPPort; smtpServerCredentials.UseSsl = currentMailServer.UseSSLforSending; smtpServerCredentials.StartTls = currentMailServer.IsStartTls; smtpServerCredentials.Timeout = currentMailServer.SMTPServerTimeout * 1000; smtpServerCredentials.SenderEmailAddress = senderEmailAddress; try { var emailClientFactory = ClassFactory.Get <EmailClientFactory>(new ConstructorArgument("userConnection", UserConnection)); IEmailSender emailSender = ClassFactory.Get <IEmailSender>( new ConstructorArgument("emailClientFactory", emailClientFactory), new ConstructorArgument("userConnection", UserConnection)); emailSender.SendTestMessage(smtpServerCredentials.SenderEmailAddress, smtpServerCredentials); } catch (SmtpException ex) { _log.Error(ex); if (!string.IsNullOrEmpty(isValidAnswer.Message)) { isValidAnswer.Message += Environment.NewLine; } isValidAnswer.IsValid = false; isValidAnswer.Message += CanNotSendTestMessageCaption.ToString() + ex.Message; } } return(isValidAnswer); }