[英]Why am I getting cannot convert from 'MimeKit.MimeMessage' to 'System.Net.Mail.MailMessage'?
I am using MimeKit for my SMTP, but I keep getting that error, when I call client.send. 我将MimeKit用于SMTP,但是在调用client.send时,我一直收到该错误。 Below is my code: 下面是我的代码:
var mailman = new MimeMessage();
var client = new SmtpClient();
//SMTP Credentials here.
// Create a new email object
mailman.From.Add(new MailboxAddress(message.FromAddress, message.FromAddress));
mailman.To.Add(new MailboxAddress(message.ToAddress, message.ToAddress));
mailman.Subject = message.MailSubject;
var builder = new BodyBuilder();
builder.HtmlBody = string.Format(message.Content);
mailman.Body = builder.ToMessageBody();
client.Send(mailman);
once I call client.Send(Mailman), I get the error. 一旦我致电client.Send(Mailman),就会收到错误消息。 Please what am I doing wrong? 请问我做错了什么?
System.Net.Mail.SmtpClient
takes a MailMessage
as a parameter ( see here ), therefor I assume that you are trying to use this SmtpClient
implementation, which is not compatible with MimeKit. System.Net.Mail.SmtpClient
将MailMessage
作为参数( 请参见此处 ),因此,我假设您正在尝试使用此SmtpClient
实现,该实现与MimeKit不兼容。 You'll have to add the MailKit NuGet package to your project and 您必须将MailKit NuGet包添加到您的项目中,然后
using MailKit.Net.Smtp;
to your source file in order to use the SmtpClient
implementation from MailKit. 到源文件,以便使用MailKit中的SmtpClient
实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.