![](/img/trans.png)
[英]ClosedXML Read excel file Error: The type initializer for 'MS.Utility.EventTrace' threw an exception. (C#)
[英]How do I fix the error “The type initializer for '?' threw an exception.” when sending e-mails through C# with EASendMail?
我一直在从事这个项目以向用户发送电子邮件,并且一直出现错误。 (我正在使用 EASendMail NuGet 包)它是“'的类型初始化程序'? 抛出异常。” (这是在 package 具有的错误系统的控制台中)我真的不知道这意味着什么,我的代码是这样的:
using EASendMail;
namespace Email
{
class Program
{
static void Main(string[] args)
{
try
{
SmtpMail oMail = new SmtpMail("TryIt");
// Set sender email address, please change it to yours
oMail.From = "Splat2ooner@gmail.com";
// Set recipient email address, please change it to yours
oMail.To = "Splat2ooner@gmail.com";
// Set email subject
oMail.Subject = "test email from c# project";
// Set email body
oMail.TextBody = "this is a test email sent from c# project, do not reply";
// SMTP server address
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
// User and password for ESMTP authentication
oServer.User = "Splat2ooner@gmail.com";
oServer.Password = "password (not my passoword)";
// Most mordern SMTP servers require SSL/TLS connection now.
// ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer.ConnectType = SmtpConnectType.ConnectTryTLS;
// If your SMTP server uses 587 port
//oServer.Port = 587;
// If your SMTP server requires SSL/TLS connection on 25/587/465 port
//oServer.Port = 25; // 25 or 587 or 465
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
Console.WriteLine("start to send email ...");
SmtpClient oSmtp = new SmtpClient();
oSmtp.SendMail(oServer, oMail);
Console.WriteLine("email was sent successfully!");
}
catch (Exception ep)
{
Console.WriteLine("failed to send email with the following error:");
Console.WriteLine(ep.Message);
}
}
}
}
谢谢。
看起来较新版本的“ EASendMail ”(截至目前最新版本是7.5.0.3 )package 有这个问题。
我没有太多时间研究它,只是安装了旧版本( 7.3.1.2 )并解决了这个问题。
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.