远程服务器返回'550 5.6.2 smtpsend.barelinefeedsareillegal;消息包含裸线馈示,无法通过数据发送'
var message = new MimeMessage();
message.From.Add(new MailboxAddress(nameFrom, mailboxFrom));
message.Subject = Subject;
message.To.Add(new MailboxAddress(mailboxTo));
var bodyBuilder = new BodyBuilder();
var multipart = new Multipart("mixed");
bodyBuilder.HtmlBody = "Test Body";
multipart.Add(bodyBuilder.ToMessageBody());
byte[] bytes = System.IO.File.ReadAllBytes("Test.gif");
var attachment = new MimePart("binary", "bin")
{
ContentObject = new ContentObject(new MemoryStream(bytes), ContentEncoding.Base64),
ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
ContentTransferEncoding = ContentEncoding.Binary,
FileName = "F2.pdf"
};
multipart.Add(attachment);
message.Body = multipart;
using (var client = new SmtpClient())
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect(ssServer, ssPort, MailKit.Security.SecureSocketOptions.Auto);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate(ssMailBox, ssMailBoxPassword);
client.Send(message);
}
我已经尝试编码contentEncoding.base64和contentencoding.binary。当我跳过附件部分时,邮件的发送正确。" test.gif"只是我上传的随机gif。
我已经阅读了有关块或bdat命令的信息,但对此不确定,或者如何将其与MailKit一起使用...有什么建议吗?我只是想发送带有附件的普通SMTP邮件,这并不难:|
解决方案是,@jstedfast建议更改:
ContentTransferEncoding = ContentEncoding.Base64
我误解了,尝试更改contentObject。
谢谢@jstedfast