jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

With version 4.4.0 I cannot send SMTP mail via Strato.de

IngoManthey opened this issue · comments

I use .Net 8.0.
My code. No exceptions were generated.

private async Task SendEmailAsync(MailboxAddress sender, MailboxAddress[] recipients, string subject, string body,
bool isHtml = true)
{
MimeMessage message = new();

message.From.Add(sender);
message.To.AddRange(recipients);
message.Subject = subject;

message.Body = !isHtml ? new TextPart("plain") { Text = body } : GetBody(body).ToMessageBody();
try
{
    using var client = new SmtpClient();
    await client.ConnectAsync(_smtpConfig.Host, _smtpConfig.Port, _smtpConfig.UseSsl);
    if (!string.IsNullOrWhiteSpace(_smtpConfig.Username))
        await client.AuthenticateAsync(_smtpConfig.Username, _smtpConfig.Password);

    await client.SendAsync(message);
    await client.DisconnectAsync(true);
}
catch (Exception ex)
{
    logger.LogError(ex, "MailManager.SendEmailAsync ");
    throw;
}

}

If I use the code with version 4.3.0 there are no problems. Am I doing something wrong???

I'll need a protocol log to analyze.

Interesting, I do have the same thing and thought it was me going from 3 to 4.4. But 4.3 is indeed working for me aswell.

How can I get the protocoll log to help you analyse? The return value of Send Async is a 200 queued with the queue id.

I am using mails by strato. I am mentioning this as Ingo seams like a german name and maybe he uses the same provider.

Ich benötige ein Protokollprotokoll zur Analyse.

I'll need a protocol log to analyze.

Hi,
How can I create a protocol that will help you? We also use strato.

Do you know where you can look up errors in strato? Maybe this could be helpful. It looks like the mail gets passed the queue but maybe there is something else happening where strato is unhappy at the end.

Do you know where you can look up errors in strato? Maybe this could be helpful. It looks like the mail gets passed the queue but maybe there is something else happening where strato is unhappy at the end.

I'm just a software developer and don't have access to strato.

Okay, I've taken a look and it looks like the issue is that a change I made to support the REQUIRETLS extension is what is causing this issue:

C: MAIL FROM:<user@domain> SIZE=278 REQUIRETLS

The REQUIRETLS extension is a really odd extension because it isn't like most other extensions where you need to opt-in. Instead, it's a feature where you need to opt-out by including a message header:

TLS-Required: No

If I add that header, it works.

it should also work if I do this before I send:

client.Capabilities &= ~SmtpCapabilities.RequireTLS;

Here's what I think the issue is:

The REQUIRETLS extension is meant to force the use of TLS from origin to the final destination.

This means that if any SMTP server between the server that the client submits the message to and the SMTP server of the recipient doesn't support REQUIRETLS, then the message fails to be delivered.

I think I'll need to add a property to SmtpClient to EnableRequireTls (or a better name).

Not sure when I'll get a chance to make a new release, so in the meantime you can either use 4.3.0 or use 4.4.0 with either of the 2 work-arounds that I mentioned in my previous comment.

When I manage to release v4.5.0, the work-arounds will no longer be necessary.

Ok nice, I will test it out tonight. Don’t know if I want to turn off tls, but I will definitely give you feedback.

thanks!

You don't need to turn off TLS to make this work.

The RequireTLS feature is unrelated to SmtpClient using TLS itself, it's a feature that tells the remote SMTP server that each hop needed to deliver the message to the final destination mailbox requires a TLS connection.

This is normally not something that is required and is why this feature is causing messages for you guys not to get delivered - SMTP servers do not implement this feature.

Ok, thanks for the explanation. Good to know that :) and thanks again for the fast replies and solution!

I have the same problem using Strato as well. I can confirm setting

client.Capabilities &= ~SmtpCapabilities.RequireTLS;

as a work-around after connecting is working for version 4.4.0.