cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
675 stars 159 forks source link

SmtpCommandException : No message provided on sending inline attachment #173

Closed alexander-bobrov closed 8 months ago

alexander-bobrov commented 2 years ago

Hi! I'm trying to receive inline attachments with this server and I keep getting errors like that: MailKit.Net.Smtp.SmtpCommandException : No message provided

If I remove the attachment part it works and that's strange.

But it works with ordinary attachments(example here: https://github.com/alexander-bobrov/MailHub/blob/c438dfb6c02959878597b795de40da646f808a78/src/Tests/SmtpTests.cs#L74)

Could u help me to find the reason?

I'm using the last version of MailKit and my test sample is: (the full code over there: https://github.com/alexander-bobrov/MailHub/blob/c438dfb6c02959878597b795de40da646f808a78/src/Tests/SmtpTests.cs#L49)

        public void SendMail_WithInlineAttachments_Should_BeOk()
        {
            var message = new MimeMessage();
            message.From.Add(new MailboxAddress("Mr.Test", "mr@test.com"));
            message.To.Add(new MailboxAddress("Mrs.Test", "mrs@test.com"));
            message.Subject = "Test message with inline attachments";

            var builder = new BodyBuilder
            {
                TextBody = "Test message"
            };

            var image = builder.LinkedResources.Add("attachment.jpg");
            image.ContentId = MimeUtils.GenerateMessageId();
            builder.HtmlBody = string.Format(@"<p>Hey!</p><img src=""cid:{0}"">", image.ContentId);

            message.Body = builder.ToMessageBody();

            using var client = new SmtpClient(new ProtocolLogger("smtp.log"));
            client.Connect("127.0.0.1", 25, false);
            client.Send(message);
            client.Disconnect(true);
        }

And smtp log here: smtp.log

alexander-bobrov commented 2 years ago

The error is on my side so it can be closed