简体   繁体   中英

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. 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. 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. You'll have to add the MailKit NuGet package to your project and

using MailKit.Net.Smtp;

to your source file in order to use the SmtpClient implementation from MailKit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM