Can not send email with SmtpClient on Ubuntu 18.4 LTS
I'm trying to send email using Google SMTP server but its throwing exception:
An unhandled exception occurred while processing the request.
Win32Exception: GSSAPI operation failed with error - An invalid status code was supplied (Unknown error).
System.Net.Security.NegotiateStreamPal.AcquireCredentialsHandle(string package, bool isServer, NetworkCredential credential)
SmtpException: Failure sending mail.
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
At Startup Class:
services.AddScoped<SmtpClient>((provider) =>
{
var config = provider.GetRequiredService<IConfiguration>();
return new SmtpClient()
{
Host = config.GetValue<String>("MailService:Smtp"),
Port = config.GetValue<int>("MailService:Port"),
Credentials = new NetworkCredential(
config.GetValue<String>("MailService:Username"),
config.GetValue<String>("MailService:Password")
)
};
});
And in Controller:
private readonly SmtpClient _smtpClient;
public ValuesController(
SmtpClient smtpClient
)
{
_smtpClient = smtpClient;
}
[HttpGet]
public async Task<IActionResult> Get()
{
await _smtpClient.SendMailAsync(new MailMessage(
from: "[email protected]",
to: "[email protected]",
subject: "Test message subject",
body: "Test message body"
));
return Ok();
}
Hello, it may not help, but can you please confirm this reproes on 2.1 (or master)? 2.0 is about to go out of support.
@danmosemsft thanks for reply. I upgraded this project to version 2.1, but there is still a similar error:
An unhandled exception occurred while processing the request.
Win32Exception: GSSAPI operation failed with error - An invalid status code was supplied (Unknown error).
System.Net.Security.NegotiateStreamPal.AcquireCredentialsHandle(string package, bool isServer, NetworkCredential credential)
SmtpException: Failure sending mail.
Thanks. Do you have a different machine to try? Not much to go on.
I tested this project on Windows Server 2012 R2 on the same network and it worked without problems.
I suspect a problem with configuration on Linux - similar to dotnet/runtime#25885 @tmds @wfurt any tips & tricks for troubleshooting?
I would suggest packet capture with wireshark or tcpdump. I would also suggest to install gss-ntlmssp package (or verify that it is in place) Just some background @shakeri: Windows do have all the necessary parts needed for NTLM and Kerberos. On Unix, this varies based on distribution and configuration.
@wfurt I installed gss-ntlmssp package and test again.It worked. Thanks.
Closing as answered.
@karelz I wonder if it would make sense for the exceptoin message to suggest installing it.
we talk about it while back @danmosemsft. I think that would be good idea.
we talk about it while back @danmosemsft. I think that would be good idea.
It's not a trivial problem to solve. The error message we get back when doing NTLM operations is not always specific enough to determine that the problem is configuration (i.e. gss-ntlmssp not installed).