简体   繁体   English

为什么我无法从“ MimeKit.MimeMessage”转换为“ System.Net.Mail.MailMessage”?

[英]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.SmtpClientMailMessage作为参数( 请参见此处 ),因此,我假设您正在尝试使用此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.

相关问题 无法从“对象”转换为“ System.Net.Mail.MailMessage” - cannot convert from 'object' to 'System.Net.Mail.MailMessage' 在 .NET 4.5 beta 中将 System.Net.Mail.MailMessage 作为 MemoryStream - Getting System.Net.Mail.MailMessage as a MemoryStream in .NET 4.5 beta 为什么我需要Dispose一个System.Net.Mail.MailMessage实例? - Why do I need to Dispose a System.Net.Mail.MailMessage instance? 使用System.Net.Mail.MailMessage时设置“发件人”地址吗? - Set “From” address when using System.Net.Mail.MailMessage? 从字符串加载System.Net.Mail.MailMessage - System.Net.Mail.MailMessage Load from a String 有没有一种简单的方法可以将Microsoft.Office.Interop.Outlook.MailItem转换为System.Net.Mail.MailMessage? - Is there an easy way to convert from Microsoft.Office.Interop.Outlook.MailItem to System.Net.Mail.MailMessage? 转换为 system.net.mail.mailMessage 错误 - converting to system.net.mail.mailMessage error 使用c#从xml获取文本时设置System.Net.Mail.MailMessage主体的编码 - setting the encoding of a System.Net.Mail.MailMessage body while getting text from xml using c# System.Net.Mail.Mailmessage可以继承吗? - Can System.Net.Mail.Mailmessage be inherited? 怎么把OpenPop.NET MailMessage转换成System.Net.Mail.MailMessage? - How to convert OpenPop.NET MailMessage to System.Net.Mail.MailMessage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM