Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTPUTF8 extension not being honoured in some (all?) cases. #649

Closed
AndrewGretton opened this issue Feb 23, 2018 · 2 comments
Closed

SMTPUTF8 extension not being honoured in some (all?) cases. #649

AndrewGretton opened this issue Feb 23, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@AndrewGretton
Copy link

Problem: when sending mail to a server that supports the SMTPUTF8 extension, using a "To" or "From" address that should require SMTPUTF8 to be emitted, SMTPUTF8 is not emitted and an error is received.

Protocol log follows:

S: 220 smtp.gmail.com ESMTP q24sm1683625qkq.75 - gsmtp
C: EHLO [127.0.0.1]
S: 250-smtp.gmail.com at your service, [1.2.3.4]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-STARTTLS
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
C: EHLO [127.0.0.1]
S: 250-smtp.gmail.com at your service, [1.2.3.4]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8
C: AUTH PLAIN ***REDACTED AUTH DETAILS***
S: 235 2.7.0 Accepted
C: MAIL FROM:<example@gmail.com>
C: RCPT TO:<ñఛ@example.com>
S: 250 2.1.0 OK q24sm1683625qkq.75 - gsmtp
S: 555 5.5.2 Syntax error. q24sm1683625qkq.75 - gsmtp
C: RSET
S: 250 2.1.5 Flushed q24sm1683625qkq.75 - gsmtp

As you can see, despite the fact that the server advertised SMTPUTF8, we didn't emit an SMTPUTF8 command anywhere and thus the server rejected our message.

Code which sent this email:

var message = new MimeMessage();
message.From.Add(new MailboxAddress("example@gmail.com"));
message.To.Add(new MailboxAddress("ñఛ@example.com"));
message.Subject = "SMTPUTF8 test";

message.Body = new TextPart("plain")
{
    Text = @"Test content"
};

using (var client = new SmtpClient(new ProtocolLogger("c:\\temp\\smtp.log")))
{
    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
    client.Connect("smtp.gmail.com", 587, false);
    client.Authenticate("example@gmail.com", "examplePassword");
    client.Send(message);
    client.Disconnect(true);
}

This problem happens with the latest version of Mailkit from Nuget as of today, using .NET Framework 4.6.1.

I had a look through SmtpClient.cs and the code looked good; though there's no corresponding test for SMTPUTF8 in SmtpClientTests.cs, so perhaps there should be :) Let me know if I missed anything, or whether I can help on a PR if you can see where the issue is.

@jstedfast
Copy link
Owner

The SMTPUTF8 extension is only used when the FormatOptions.International property is set to true.

In other words, you need to do this:

var options = FormatOptions.Default.Clone ();
options.International = true;

client.Send (options, message);

@jstedfast
Copy link
Owner

MailKit 2.0.2 has been released with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants