首页 > 解决方案 > C# - Linux 上的 SMTP 邮件发送不起作用

问题描述

我的程序在 debian 10 Linux 服务器上运行。

我在我的 C# 程序中使用了一个名为 EASendMail 的包,但它也不适用于普通的 System.Net.Mail。

这是我用于发送邮件的代码片段

SmtpMail oMail = new SmtpMail("mykey");

                oMail.From = fromEmail;
                oMail.To = toEmail;

                oMail.Subject = "Subject";
                oMail.TextBody = "Body";

                SmtpServer oServer = new SmtpServer(exchange);
                oServer.User = email;
                oServer.Password = pass;
                oServer.Port = 25;
                

                Console.WriteLine("start to send email ...");

                SmtpClient oSmtp = new SmtpClient();
                oSmtp.SendMail(oServer, oMail); 

                Console.WriteLine("email was sent successfully!");

每次我在 linux 上启动我的程序时dotnet run,整个 porgram 都能完美运行。如果它来做 smtp 部分,则会出现此错误:Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory

我知道 kernel32.dll 仅适用于 Windows,但有什么解决方法吗?

提前致谢!!

标签: c#linuxsmtpeasendmail

解决方案


推荐阅读