views:

380

answers:

3

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

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

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

Would this work anyway?

A: 

The problem with this approach is that you'll be changing the email addresses.

The email addresses [email protected] and bevä[email protected] are different email addresses, however much they appear the same.

Making the change you suggest will break email - people might receive the messages, but they won't be able to reply to them.

Your SMTP server that doesn't handle accented characters sounds like a dinosaur. Much as it might be a pain in the proverbial, replacement and/or upgrade is likely the best solution.

You'll likely be able to get more appropriate assistance over on ServerFault.

Bevan
It's not a "dinosaur" - it's just following RFC 822.
Jon Skeet
+2  A: 

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;
    }
}

In app.config:

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

Result:

xn--caf-dma.com
Jon Skeet
Added the C# code but it does not work as the domain name is returned as it is, where shall I add the configuration settings for ASP.net application as adding this in web.config gives error.
Pranali Desai
Is it possible to achieve this without making changes to machine.config?
Pranali Desai
@Pranali: I *believe* there's something in the IIS configuration which lets you specify the configuration to use for an ASP.NET web site... not sure.
Jon Skeet
A: 

RFC821 and RFC822 are quite old, even RFC2822 is made obsolete. But at least up till RFC2821 and RFC2822, the SMTP address can only contain a subset of ASCII chars. If you look at http://en.wikipedia.org/wiki/E-mail_address and section "Internationalization". You will see what has been happening. It's important to check the support of the new standards of your current MTA.

I don't exactly understand your use case. The user is directly interfacing with your MTA? Were you able to assign them the SMTP address with accented char when setting him up?

Junping