Convert non-ascii domain to SMTP compatible

When customers enter email addresses with non-ascii characters such as Àüâ, our SMTPs refuse to process them.

So, I think, maybe there is a solution to process these domains yourself and convert them to punyocode.

Is there an easy way to do this with C #?

Will this work?

+3
source share
2 answers

You can use Uri.DnsSafeHostto convert to Punycode:

using System;

class Test
{
    static void Main()
    {
        Console.WriteLine(ConvertToPunycode("caf\u00e9.com"));
    }

    static string ConvertToPunycode(string domain)
    {
        Uri uri = new Uri("http://"+domain);
        return uri.DnsSafeHost;
    }
}

In app.config:

<configuration>
  <uri>
    <idn enabled="All" />
  </uri>
</configuration>

Result:

xn--caf-dma.com
+8
source

The problem with this approach is that you will change email addresses.

bevan@example.com bevΓ€n@example.com - , .

, , - , .

SMTP-, , . , , / , , .

, ServerFault.

0

Source: https://habr.com/ru/post/1720539/


All Articles