1

I use C# code to send email. In some rare cases an invalid email address appears like

fréderique@gmail.com which is denied by SMTP server as non-ASCII email address.

I would like to 'normalize' this address from fréderique@gmail.com to frederique@gmail.com

I can, of course, write hardcoded map where I strictly define é => e etc but I would like to make it cleaner if possible.

Is there any .NET class for this?

Thanks

Luke1988
  • 1,595
  • 1
  • 18
  • 36
  • 5
    What does normalizing help when the email is still invalid? non-ascii characters are valid in emails - https://stackoverflow.com/questions/760150/can-an-email-address-contain-international-non-english-characters – Rand Random Jan 21 '22 at 14:59
  • I think you need to write an extension method to rewrite special characters. – Maytham Fahmi Jan 21 '22 at 15:04
  • 5
    Are you sure that the email address will still be valid after doing the rewrite? Have you confirmed that emails to `fréderique@gmail.com` and `frederique@gmail.com` end up in the same mailbox? – canton7 Jan 21 '22 at 15:09
  • But if you - for what ever reason - believe the email gets valid - here you may find a solution: https://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net – Rand Random Jan 21 '22 at 15:10
  • 5
    I would strongly advise against essentially guessing alternative email addresses. Either don't accept that address to begin with or change to a smtp server that supports a bigger set of valid addresses. – oriberu Jan 21 '22 at 15:12
  • 2
    `fréderique@gmail.com` and `frederique@gmail.com` are both valid email addresses and they are different from each other. So if you change characters in the original email address and send email the email will end up in completely different email inbox. So you should use SMTP server which supports such characters in email address – Chetan Jan 21 '22 at 15:16
  • Understand. Well, such similair address has been rejected by our SMTP provider as invalid non-ASCII email address. To be honest, I have never ever seen such non-simple characters email address so my first tought was to "normalize" as the best way. However, I will rethink it again – Luke1988 Jan 21 '22 at 19:32

0 Answers0