Добрый день!
Столкнулся с такой проблемой: пытаюсь отправить письмо из бизнес процесса, а получаю ошибку.
Ошибка следующая:
Terrasoft.Mail.Sender.EmailException: Плохие данные.
---> System.Security.Cryptography.CryptographicException: Плохие данные.
в System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
в System.Security.Cryptography.Utils._DecryptData(SafeKeyHandle hKey, Byte[] data, Int32 ib, Int32 cb, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode PaddingMode, Boolean fDone)
в System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
в System.Security.Cryptography.CryptoStream.FlushFinalBlock()
в System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing)
в System.IO.Stream.Close()
в Terrasoft.Core.SecureTextDataValueType.GetValueForLoad(UserConnection userConnection, Object value)
в Terrasoft.Core.Entities.EntityColumnValue.LoadValue(Object value)
в Terrasoft.Core.Entities.EntityColumnValueCollection.ForceLoadColumnValue(String name, Object value)
в Terrasoft.Core.Entities.Entity.LoadShallow(IDataReader dataReader, Dictionary`2 columnMap)
в Terrasoft.Core.Entities.EntityCollection.LoadShallow(IDataReader dataReader, Dictionary`2 columnMap, Boolean needClear)
в Terrasoft.Core.Entities.EntitySchemaQuery.GetEntitySchemaEntityCollection(UserConnection userConnection, IDataReader dataReader)
в Terrasoft.Core.Entities.EntitySchemaQuery.GetEntityCollection(UserConnection userConnection)
в Terrasoft.Mail.SmtpClient.CreateMailCredentialByAddress(String address, Boolean ignoreRights)
в Terrasoft.Mail.SmtpClient.CreateSmtp(String address, Boolean ignoreRights)
в Terrasoft.Mail.SmtpClient.Send(EmailMessage emailMessage, Boolean ignoreRights)
--- Конец трассировки внутреннего стека исключений ---
в Terrasoft.Mail.SmtpClient.Send(EmailMessage emailMessage, Boolean ignoreRights)
в Terrasoft.Core.Process.Configuration.AutoEmailUserTaskSender.Execute(IEmailUserTaskMessageProvider messageProvider, ProcessExecutingContext context)
в Terrasoft.Core.Process.Configuration.EmailTemplateUserTask.InternalExecute(ProcessExecutingContext context)
в Terrasoft.Core.Process.ProcessActivity.Execute(ProcessExecutingContext context)
При разборе полётов определил что исключение вываливается в методе CreateMailCredentialByAddress класса SmtpClient, строка mailboxESQ.GetEntityCollection(_userConnection);
private MailCredentials CreateMailCredentialByAddress(string address, bool ignoreRights = false) {
var mailboxESQ = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "MailboxSyncSettings");
EntitySchemaQueryColumn userNameColumn = mailboxESQ.AddColumn("UserName");
EntitySchemaQueryColumn userPasswordColumn = mailboxESQ.AddColumn("UserPassword");
EntitySchemaQueryColumn isAnonymousAuthentication = mailboxESQ.AddColumn("IsAnonymousAuthentication");
EntitySchemaQueryColumn sendEmailsViaThisAccountColumn = mailboxESQ.AddColumn("SendEmailsViaThisAccount");
EntitySchemaQueryColumn smtpHostColumn = mailboxESQ.AddColumn("MailServer.SMTPServerAddress");
EntitySchemaQueryColumn smtpPortColumn = mailboxESQ.AddColumn("MailServer.SMTPPort");
EntitySchemaQueryColumn smtpSslColumn = mailboxESQ.AddColumn("MailServer.UseSSLforSending");
EntitySchemaQueryColumn smtpTimeoutColumn = mailboxESQ.AddColumn("MailServer.SMTPServerTimeout");
IEntitySchemaQueryFilterItem senderEmailAddressFilter = mailboxESQ
.CreateFilterWithParameters(FilterComparisonType.Equal, "SenderEmailAddress", address);
mailboxESQ.Filters.Add(senderEmailAddressFilter);
if (ignoreRights) {
mailboxESQ.UseAdminRights = false;
} else {
mailboxESQ.AddRightsFilters(_userConnection.CurrentUser.Id);
}
EntityCollection mailboxEntities = mailboxESQ.GetEntityCollection(_userConnection);
var mailCredentials = new MailCredentials();
if (mailboxEntities.Count == 0) {
throw new Sender.EmailException("ErrorOnSend", MailboxDoesNotExist);
}
Entity mailbox = mailboxEntities[0];
if (!mailbox.GetTypedColumnValue(sendEmailsViaThisAccountColumn.Name)) {
throw new Sender.EmailException("ErrorOnSend", NotAllowedSendingFromThisMailbox);
}
mailCredentials.Host = mailbox.GetTypedColumnValue(smtpHostColumn.Name);
mailCredentials.Port = mailbox.GetTypedColumnValue(smtpPortColumn.Name);
mailCredentials.UserName = mailbox.GetTypedColumnValue(userNameColumn.Name);
mailCredentials.UserPassword = mailbox.GetTypedColumnValue(userPasswordColumn.Name);
mailCredentials.UseSsl = mailbox.GetTypedColumnValue(smtpSslColumn.Name);
mailCredentials.Timeout = mailbox.GetTypedColumnValue(smtpTimeoutColumn.Name) * 1000;
mailCredentials.IsAnonymousAuthentication = mailbox.GetTypedColumnValue(isAnonymousAuthentication.Name);
return mailCredentials;
}