[英]How can I send an email with MimeKit in C#
Hi everyone I'm trying to send an email using the MimeKit but I'm trying to attach a.pdf file I have some problems:大家好我正在尝试使用 MimeKit 发送一个 email 但我正在尝试附加一个 .pdf 文件我有一些问题:
This is how I'm trying to send it:这就是我尝试发送它的方式:
private bool EnviarMail(string file, string from, string to, string subject, string content, string name)
{
bool estado = false;
try
{
var mensaje = new MimeMessage();
mensaje.From.Add(new MailboxAddress(name, from));
mensaje.To.Add(new MailboxAddress("", to));
mensaje.Subject = subject;
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = content;
bodyBuilder.Attachments.Add(file);
mensaje.Body = bodyBuilder.ToMessageBody();
using (var client = new SmtpClient("myHost", myPort))
{
client.Send(mensaje);
}
estado = true;
return estado;
}
catch (Exception ex)
{
return estado;
}
}
But I have this error on client.send(mensaje)
line.但是我在
client.send(mensaje)
行有这个错误。 It says:它说:
Argument 1: cannot convert from 'MimeKit.MimeMessage' to ' System.Net.Mail.MailMessage'
参数 1:无法从“MimeKit.MimeMessage”转换为“System.Net.Mail.MailMessage”
How can I send this email correctly?我怎样才能正确发送这个 email?
I tried what is was told here: Can I send files via email using MailKit?我尝试了这里所说的: Can I send files via email using MailKit?
But I couldn't do it for same error但是我不能因为同样的错误而做
The error indicates that you are using the wrong SMTP client!报错说明你用错了SMTP客户端!
You should be using the one that comes with MimeKit ( MailKit.Net.Smtp.SmtpClient ) and not the one in .NET ( System.Net.Mail.SmtpClient )您应该使用 MimeKit 附带的那个 ( MailKit.Net.Smtp.SmtpClient ) 而不是 .NET ( System.Net.Mail.SmtpClient ) 中的那个
Note that MimeKit and MailKit work hand-in-hand with MimeKit devoted to the parsing and handling of messages.请注意,MimeKit 和 MailKit 与 MimeKit 携手合作,致力于消息的解析和处理。 Where as MailKit concerns the.network aspects of sending and receiving messages.
MailKit 关注发送和接收消息的网络方面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.