将非ascii域转换为SMTP兼容 [英] Convert non-ascii domain to SMTP compatible

查看:124
本文介绍了将非ascii域转换为SMTP兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当客户输入带有非ASCII字符(例如äüö)的电子邮件地址时,我们的SMTP拒绝处理它们.

When customers enter email addresses with non-ascii chars like äüö our SMTP rejects to process them.

因此,我认为可能存在一种解决方案,可以自己处理这些域并将其转换为punyocode.

So I think might be there is a solution to handle those domains myself and convert them to punyocode.

是否有使用c#的简单方法?

Is there a simple way of doing so using c#?

反正这项工作吗?

推荐答案

您可以使用 Uri.DnsSafeHost 转换为Punycode:

You can use Uri.DnsSafeHost to 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;
    }
}

在app.config中:

In app.config:

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

结果:

xn--caf-dma.com

这篇关于将非ascii域转换为SMTP兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆