SmtpServer icon indicating copy to clipboard operation
SmtpServer copied to clipboard

SmtpCommandException : No message provided on sending inline attachment

Open alexander-bobrov opened this issue 3 years ago • 1 comments

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", "[email protected]"));
            message.To.Add(new MailboxAddress("Mrs.Test", "[email protected]"));
            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 avatar Feb 23 '22 12:02 alexander-bobrov

The error is on my side so it can be closed

alexander-bobrov avatar Feb 28 '22 11:02 alexander-bobrov