我有一个Windows服务,需要在某个时间点发送电子邮件。 当我尝试初始化SmtpClient时,我收到错误“配置系统无法初始化”。
知道如何解决这个问题吗?
SMTP客户端初始化
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = Int32.Parse(smtpPort);
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
smtpClient.Host = smtpHost;
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<!-- Log4Net Configuration -->
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\ArchiveService.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level - %message%newline" />
</layout>
</appender>
</log4net>
<appSettings>
</appSettings>
</configuration>