设置 EmailSettingNames.Smtp.EnableSsl 导致 "String was not recognized as a valid Boolean" 错误
setting EmailSettingNames.Smtp.EnableSsl results in a "String was not recognized as a valid Boolean" error
我已经设置了 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)
};
}
}
但是当我发送电子邮件时,它会生成一个 "String was not recognized as a valid Boolean" 异常,我还如何定义 EmailSettingNames.Smtp.EnableSsl 属性 以便它正确应用?
下面是正确的:
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
不能为空字符串。
我已经设置了 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)
};
}
}
但是当我发送电子邮件时,它会生成一个 "String was not recognized as a valid Boolean" 异常,我还如何定义 EmailSettingNames.Smtp.EnableSsl 属性 以便它正确应用?
下面是正确的:
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
不能为空字符串。