настройка EmailSettingNames.Smtp.EnableSsl приводит к ошибке «Строка не была распознана как допустимая логическая ошибка» - PullRequest
0 голосов
/ 27 октября 2019

Я настроил шаблон aspnet для отправки писем. Я установил значения по умолчанию, используя следующее:

    public class AppSettingProvider : SettingProvider
{
    public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
    {
        return new[]
        {
            new SettingDefinition(EmailSettingNames.DefaultFromAddress, "", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.DefaultFromDisplayName, "", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Host, "127.0.0.1", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Port, "25", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.UserName, XXXXX, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Password, XXXXX, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Domain, string.Empty, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.EnableSsl, "true", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.UseDefaultCredentials, string.Empty, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true)
        };
    }
}

Но когда я отправляю электронное письмо, оно генерирует исключение «Строка не была распознана как допустимое логическое значение», как еще я могу определить EmailSettingNames.Smtp. Свойство EnableSsl, чтобы оно правильно применялось?

1 Ответ

1 голос
/ 28 октября 2019

Ниже приведено правильное значение:

public class AppSettingProvider : SettingProvider
{
    public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
    {
        return new[]
        {
            new SettingDefinition(EmailSettingNames.DefaultFromAddress, "", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.DefaultFromDisplayName, "", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Host, "127.0.0.1", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Port, "25", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.UserName, XXXXX, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Password, XXXXX, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.Domain, string.Empty, scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.EnableSsl, "true", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true),
            new SettingDefinition(EmailSettingNames.Smtp.UseDefaultCredentials, "false", scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User, isVisibleToClients: true, isInherited: true)
        };
    }
}

Исправлено: UseDefaultCredentials не может быть пустой строкой.

...