public virtual void SendEmailWithDefaultSender(EmailMessage emailMessage, bool ignoreErrors) { var userConnectionArg = new ConstructorArgument("userConnection", UserConnection); var emailClientFactory = ClassFactory.Get <EmailClientFactory>(userConnectionArg); if (UserConnection.GetIsFeatureEnabled("EmailIntegrationV2")) { var sender = new ActivityEmailSender(emailClientFactory, UserConnection); sender.Send(emailMessage, true); } else { var credentials = new Terrasoft.Mail.MailCredentials { Host = (string)SysSettings.GetValue(UserConnection, "SmtpHost"), Port = int.Parse(SysSettings.GetValue(UserConnection, "SmtpPort").ToString()), UseSsl = (bool)SysSettings.GetValue(UserConnection, "SmtpEnableSsl"), UserName = (string)SysSettings.GetValue(UserConnection, "SmtpUserName"), UserPassword = (string)SysSettings.GetValue(UserConnection, "SmtpUserPassword") }; try { var emailClientFactoryArg = new ConstructorArgument("emailClientFactory", emailClientFactory); var emailSener = ClassFactory.Get <IEmailSender>(emailClientFactoryArg, userConnectionArg); emailSener.Send(emailMessage, credentials); } catch (Exception e) { _log.Error(e); if (!ignoreErrors) { throw; } } } }
public virtual Terrasoft.Mail.ImapClient GetInitializedImapClient() { #if !NETSTANDARD2_0 // TODO CRM-42546 var select = new Select(UserConnection) .Column("MS", "Address").Column("MS", "Port").Column("MS", "UseSSL") .Column("MSS", "UserName").Column("MSS", "UserPassword") .From("MailServer").As("MS") .InnerJoin("MailboxSyncSettings").As("MSS").On("MSS", "MailServerId").IsEqual("MS", "Id") .InnerJoin("ActivityFolder").As("AF").On("AF", "Name").IsEqual("MSS", "UserName") .Where("AF", "Id").IsEqual(Column.Parameter(Entity.GetTypedColumnValue <Guid>("ParentId"))) as Select; var serverCredentials = new Terrasoft.Mail.MailCredentials(); using (var dbExecutor = UserConnection.EnsureDBConnection()) { using (var dataReader = select.ExecuteReader(dbExecutor)) { if (dataReader.Read()) { serverCredentials.Host = (string)dataReader[0]; serverCredentials.Port = (int)dataReader[1]; serverCredentials.UseSsl = (bool)dataReader[2]; serverCredentials.UserName = (string)dataReader[3]; serverCredentials.UserPassword = (string)UserConnection.DataValueTypeManager .GetInstanceByName("SecureText").GetValueForLoad(UserConnection, (string)dataReader[4]); } } } return(new Terrasoft.Mail.ImapClient(serverCredentials, new Terrasoft.Mail.ImapErrorMessages(), UserConnection)); #else throw new NotImplementedException(); #endif }
private static Terrasoft.Mail.MailCredentials CreateMailCredentials(UserConnection userConnection) { var smtpHost = (string)SysSettings.GetValue(userConnection, "SmtpHost"); var smtpPort = (int)SysSettings.GetValue(userConnection, "SmtpPort"); var smtpUserName = (string)SysSettings.GetValue(userConnection, "SmtpUserName"); var smtpUserPassword = (string)SysSettings.GetValue(userConnection, "SmtpUserPassword"); var enableSsl = (bool)SysSettings.GetValue(userConnection, "SmtpEnableSsl"); var credentials = new Terrasoft.Mail.MailCredentials() { Host = smtpHost, Port = smtpPort, UseSsl = enableSsl, UserName = smtpUserName, UserPassword = smtpUserPassword }; if (smtpHost.IsNullOrEmpty() || smtpUserName.IsNullOrEmpty()) { string errorMessage = GetLocalizableString(userConnection, "MailNotConfigured"); throw new ArgumentNullOrEmptyException(errorMessage, null); } return(credentials); }