15

I am generating and sending email using C#.

The mail message is html formatted, and everything appears fine just before the Send method is called i.e. there is only a single dot just before aspx in the href URL, but when I open the sent email in Outlook or any other email client, it shows a double dot for a href as in code below.

<a href='http://localhost/xyz/invitation..aspx?invitecode=92EFB482-1792-4BC6-9507-70D2E3F06FE0'>Click Here </a>

My question: Why would this be happening, and is there any way to resolve this problem like some special encoding for MailMessage.BodyEncoding ? I am using the default encoding (ASCII) for MailMessage.BodyEncoding.

Sunil
  • 20,653
  • 28
  • 112
  • 197
  • 1
    Try using UTF8 encoding [check this out] (http://stackoverflow.com/questions/6602318/system-net-mail-creating-invalid-emails-and-eml-files-inserting-extra-dots-in-h) – NMK Sep 22 '14 at 16:57
  • Thanks. That seems very similar to my problem. Let me try and I will get back soon. – Sunil Sep 22 '14 at 17:00
  • Yes, that worked. Can you post this so I can mark it as answer? Also, I guess changing it to UTF8 will be fine in web mail clients like gmail, yahoo and web outlook. – Sunil Sep 22 '14 at 17:09

1 Answers1

28

Try using UTF8 encoding. This should work

mail.BodyEncoding = System.Text.Encoding.UTF8;
NMK
  • 1,010
  • 10
  • 18
  • My problem was that when I was calling var mail = new MailMessage(from, to, subject, body); some times encoding was UTF-8 some other times ASCII. I don't know why that was happening but by setting encoding UTF-8, the problem with the double dots was resolved. – user3417479 Nov 20 '18 at 15:04