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

Mailkit 2.1.2 + .Net 4.5.2 Error on SmtpClient.Connect #814

Closed
Alexboxat opened this issue Feb 6, 2019 · 14 comments
Closed

Mailkit 2.1.2 + .Net 4.5.2 Error on SmtpClient.Connect #814

Alexboxat opened this issue Feb 6, 2019 · 14 comments
Labels
compatibility Compatibility with existing software

Comments

@Alexboxat
Copy link

Desktop:

  • Windows 7 SP1 x32 x64
  • Mailkit 2.1.2
  • .Net Framework 4.5.2 (there is no error with 4.6 and 4.7)

To Reproduce

  1. Try to connect to any SMTP server:
    client.Connect("smtp.gmail.com", 587, SecureSocketOptions.Auto);

I get Exception:

Specified argument was out of the range of valid values.
Parameter name: newAddress

at
SmtpClient.Connect at System.Net.IPAddress..ctor(Int64 newAddress)
at System.Net.IPAddress.MapToIPv4()
at MailKit.Net.Smtp.SmtpClient.d__61.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MailKit.Net.Smtp.SmtpClient.d__62.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at MailKit.Net.Smtp.SmtpClient.d__70.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MailKit.Net.Smtp.SmtpClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)

@jstedfast jstedfast transferred this issue from jstedfast/MimeKit Feb 6, 2019
@jstedfast
Copy link
Owner

This is the only place MailKit calls MapToIPv4(): https://github.com/jstedfast/MailKit/blob/master/MailKit/Net/Smtp/SmtpClient.cs#L437

However, this is not in the Connect() method so I'm not sure that's the issue.

Could you debug this and check if that is the right place?

@Alexboxat
Copy link
Author

Alexboxat commented Feb 7, 2019 via email

@Alexboxat
Copy link
Author

Alexboxat commented Feb 7, 2019 via email

@jstedfast
Copy link
Owner

Looks like some versions of .NET have a bug: https://stackoverflow.com/questions/23608829/why-does-ipaddress-maptoipv4-throw-argumentoutofrangeexception

Check out the accepted answer to that StackOverflow question.

What environment are you running .NET 4.5.2? Is it running on Windows? Mac? Linux? Is it using Mono or CoreCLR?

I wonder if it has all of the service packs installed?

@Alexboxat
Copy link
Author

Alexboxat commented Feb 8, 2019 via email

jstedfast added a commit that referenced this issue Feb 9, 2019
@jstedfast jstedfast added the compatibility Compatibility with existing software label Feb 9, 2019
@jstedfast
Copy link
Owner

Can you try building the latest revision to see if that fixes things for you?

I don't want to make a release only to find out it doesn't fix the issue.

Thanks.

@Alexboxat
Copy link
Author

Alexboxat commented Feb 11, 2019 via email

@GraemeMorton
Copy link

@jstedfast I was getting the above problem and your change resolved it ... however I am now getting another error but that may be unrelated :)

@jstedfast
Copy link
Owner

What problem are you getting now?

@GraemeMorton
Copy link

It was a "relay access denied" error but I think it was the wrong relay server for that specific part of the network so it is resolved now as well :)

@jstedfast
Copy link
Owner

ok

@niemyjski
Copy link

niemyjski commented Jun 5, 2019

Just an update... I was able to get connected using the following code:

await client.ConnectAsync("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect, cancellationToken);
            
var oauth2 = new SaslMechanismOAuth2(username, apiKey);
await client.AuthenticateAsync(oauth2, cancellationToken);

@KrishnaramaGit
Copy link

KrishnaramaGit commented Aug 29, 2019

Hello,

I was getting an exception in our production environment as "Method not found: '!!0[] System.Array.Empty()'." at the time of connecting,
client.Connect("smtp.gmail.com", 587, SecureSocketOptions.Auto);
While searching for the issue it is showing me to upgrade the framework version. But its working fine in the development and UAT.

Could you please help me to resolve the issue or did I miss anything.

Thanks in advance.

@jstedfast
Copy link
Owner

@KrishnaramaGit you somehow managed to leave out all of the important details of the issue you are hitting :-\

  1. What is the StackTrace of the exception you are hitting?
  2. What version of .NET are you using in production?
  3. What version of .NET are you using in development?

My guess is that you are compiling your program on a system with a newer version of .NET than your production machine has, and so even though your development machine has Array.Empty, your production machine does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with existing software
Projects
None yet
Development

No branches or pull requests

5 participants