Hi,
I'm trying to send a mail using MailKit from my WebAPI but keep getting this error
On .NETCore 3:
ExtendedSocketException: nodename nor servname provided, or not known
And on .NetCore 2:
Device Not Configured
This error is what made me test the .NET Core 3
This is my current system configuration
OS: macOS Mojave (10.14.5)
.NET Core (SDK): 3.0.100-preview5-011568
.NET Core (Runtime): 3.0.0-preview5-27626-15
Visual Studio for Mac: 8.1 Preview (8.1 build 2460)
Connected to the router by WiFi
Are you able to isolate the problem without MailKit? We want to make sure it is not MailKit problem before we start investigating.
Tested with the following code that uses the import using System.Net.Mail;
```c#
var smtpClient = new SmtpClient
{
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = "smtp.google.com",
EnableSsl = true,
Credentials = new System.Net.NetworkCredential("
MailAddress sendTo = new MailAddress("
MailMessage mail = new MailMessage(from, sendTo)
{
BodyEncoding = Encoding.UTF8,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure,
Subject = "test",
Body = "testing mail .NET Core 3"
};
smtpClient.Send(mail);
```
I'm sure that the code works, I've tested on my Windows machine using .NET Core 2.0, also triple checked the credentials, port and host.
Still the same error occurs
ExtendedSocketException: nodename nor servname provided, or not known
System.Net.Dns.InternalGetHostByName(string hostName)SmtpException: Failure sending mail.
System.Net.Mail.SmtpClient.Send(MailMessage message)

ExtendedSocketException: nodename nor servname provided, or not known
We have seen this type of error before on MacOS. It is some kind of DNS resolution problem.
ExtendedSocketException: nodename nor servname provided, or not known
We have seen this type of error before on MacOS. It is some kind of DNS resolution problem.
I've read that, but it happened on .NET Core 2.2 and apparently it still isn't fixed.
My Mac is properly configured and there are no problems in the internet I've already cleaned the DNS cache in case it was corrupted somehow but still the same.
This is clearly DNS lookup failure. I was tracing something this while back and sometimes OS simply returns failure. I did not find any good way aside from retry how to fix it. You can try to use NameResolution directly and check what you getting.
Apparently the problem is fixed, don't know if it was an macOS update that fixed or an VS update but now it's working.
The problem still happen on OSX with .Net Core 3.1
The problem still happen on OSX with .Net Core 3.1
I'm running the latest version of OSX and .NET Core (3.1) and I didn't run into problems
Have you tried to clear your DNS and test with another network?
It happens on my home network over wifi, over wire, at office, and even on Starbucks wifi...
Can you run this small program and tell me the output?
using System;
using System.Net;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Dns.GetHostName());
Console.WriteLine(Dns.GetHostEntryAsync(Dns.GetHostName()).GetAwaiter().GetResult().AddressList[0]);
}
}
}

Dns.GetHostName() return the right macbook name but GetHostEntryAsync(hostname) is what explodes...
I'm unable to replicate the problem...
Try editing your hosts file /etc/hosts and add <your network ip> GUTO-MBP or 127.0.0.1 GUTO-MBP
Looks like it worked @PedroCavaleiro
Thanks!
@PedroCavaleiro on .Net Core 3.1.201 I'm getting this same error nodename nor servname provided, or not known on my mac. I get the following output from the program you posted above.
Alejandros-MBP.attlocal.net
192.168.1.73
Modifying my /etc/hosts file doesn't seem to solve the problem.
Any idea what the issue here might be?
@PedroCavaleiro on .Net Core 3.1.201 I'm getting this same error nodename nor servname provided, or not known on my mac. I get the following output from the program you posted above.
Alejandros-MBP.attlocal.net
192.168.1.73
Modifying my /etc/hosts file doesn't seem to solve the problem.
Any idea what the issue here might be?
A couple of questions,
I'm assuming Alejandros-MBP.attlocal.net is your computer right?
what is the change that you did to your hosts file?
Something like this?
127.0.0.1 Alejandros-MBP.attlocal.net
Or did you use your network IP?
Have you tried to clean your DNS Cache?
If not, on terminal sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder or use a 3rd party program to clean the DNS Cache
@PedroCavaleiro I tried both resolving my network IP and my localhost address to the Dns.GetHostName() value (Alejandros-MBP.attlocal.net) and got the same response. I tried clearing the DNS cache, but that didn't work either.
I assume that the output that you've provided comes from this code
C#
Console.WriteLine(Dns.GetHostName());
Console.WriteLine(Dns.GetHostEntryAsync(Dns.GetHostName()).GetAwaiter().GetResult().AddressList[0]);
If so it means that the name is being properly resolved or else you wouldn't get the IP resolved.
You would have the hostname in this case Alejandros-MBP.attlocal.net but then it would crash with that exception, so you wouldn't know the IP, the problem lies elsewhere.
Can I see part of the code where the exception is thrown?
Are you also sure that you're targeting the right framework, I know it sounds like a dumb question but it's not the first time where I see someone installing a more recent framework and forgetting to target it. If you're using Visual Studio check the project properties if you're using VSCode open your .csproj file and check for this area

I currently have a project targeting that framework and I don't have any issues so far
@PedroCavaleiro Yup I'm targeting my installed version - .Net core 3.1. I simply followed the named client documentation here to set up my client and make a post requests.
My class looks something like this
using System;
using System.Collections.Generic;
using System.Net.Http;
using ExternalDataSetsApi.Contracts;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Task = System.Threading.Tasks.Task;
namespace ExternalDataSetsApi.Services
{
public class DeviceService : IDeviceService
{
private readonly IHttpClientFactory _clientFactory;
private readonly string _apiKey;
private readonly ILogger<DeviceService> _logger;
private readonly string _loginUrl;
public DeviceService(IConfiguration configuration, ILogger<DeviceService> logger,
IHttpClientFactory clientFactory)
{
_apiKey = configuration["umls:apiKey"];
_loginUrl = configuration["umls:loginUrl"];
_clientFactory = clientFactory;
}
private async Task GetTicketGrantingTicket()
{
try
{
var postBody = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("apiKey", _apiKey),
});
var client = _clientFactory.CreateClient("umls");
var response = await client.PostAsync(new Uri(_loginUrl), postBody);
response.EnsureSuccessStatusCode();
}
catch (Exception e)
{
_logger.LogError(e.Message);
throw;
}
}
}
}
And my named client is injected like this
services.AddHttpClient("umls", client =>
{
client.Timeout = TimeSpan.FromSeconds(30);
client.DefaultRequestHeaders.Add("Accept", "*/*");
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
client.DefaultRequestHeaders.Add("User-Agent", "CareCloud");
});
The server, is it running on your computer or is it running on your network, if it's on your network are you accessing with IP or computer name because if it's not running on your computer and you try to access it though name it might have not been resolved.
If the server is not running on your computer open the terminal and do a simple ping if it fails you know that .NET Core is not your culprit here if it gets an answer try using the IP if you're not already.
If it's running on your computer maybe try localhost, or 127.0.0.1, if you haven't tried already, as server address if none of these work I can't be of more help.
Also check your firewall (if you have macOS's native one or a 3rd party one) enabled. Just try disabling for a test.
Its running on my laptop. I'll see if disabling the firewall helps. Thanks for your help.
Its running on my laptop. I'll see if disabling the firewall helps. Thanks for your help.
Let me know how it works out.
Glad to help, or at least try
Most helpful comment
I'm unable to replicate the problem...
Try editing your hosts file
/etc/hostsand add<your network ip> GUTO-MBPor127.0.0.1 GUTO-MBP