MailKit.Net.Smtp.SmtpClient.Send 在 Linux 上不能运行的原因可能有以下几点:
dotnet --version
命令来检查你的 .NET Core 版本。如果需要,可以通过以下命令安装合适的版本:sudo apt-get update
sudo apt-get install -y dotnet-sdk-3.1
System.Security.Cryptography.Native.OpenSsl
包。你可以通过以下命令安装:dotnet add package System.Security.Cryptography.Native.OpenSsl
using MailKit.Net.Smtp;
using MimeKit;
class Program
{
public static async Task Main(string[] args)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("From Name", "from@example.com"));
message.To.Add(new MailboxAddress("To Name", "to@example.com"));
message.Subject = "Hello!";
var bodyBuilder = new BodyBuilder();
bodyBuilder.TextBody = "This is a test email.";
message.Body = bodyBuilder.ToMessageBody();
using var smtpClient = new SmtpClient();
smtpClient.Connect("smtp.example.com", 587, true);
smtpClient.Authenticate("username", "password");
await smtpClient.SendAsync(message);
smtpClient.Disconnect(true);
}
}
领取专属 10元无门槛券
手把手带您无忧上云