SmtpClient.send(MailMessage) is adding an extra period in the body text of the email
Asked Answered
U

0

8

I'm using System.Net.Mail.SmtpClient.

I build my MailMessage. IsBodyHtml is set to true. The Body is some html with some links.

Occasionally, some strange behavior occurs - an extra period will get added to one of the links. for example, the link will be set to this in the MailMessage Body:

<a href="http://www.myapp.com/company/contact">Contact Us</a>

but the email received shows up with an extra period:

<a href="http://www.myapp..com/company/contact">Contact Us</a>

The really strange behavior is that sometime the extra period will be added to a different link and sometimes it won't be added at all!

Is this a bug with System.Net.Mail.SmtpClient? Because the Body in the MailMessage does not have the extra period right as it's sent:

_smtp.Send(message); //message.Body has no extra period during sending

Note, I am using DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory which is writing the email to a file.

Update: I'm don't think this actually fixed it, but by setting message.BodyEncoding = System.Text.Encoding.UTF8;, I can't seem to reproduce the bug. Any ideas why that may have fixed it?

Uncinate answered 10/11, 2016 at 17:39 Comment(13)
Never had that happen to me before. Are you setting IsBodyHtml?Kaiserslautern
@Kaiserslautern IsBodyHtml is set to true. Yeah it's really strange.Uncinate
Are you hard coding the href in anchor tag or is it generated by some other method. This is really weird if it's happening after hard coding the href.Sharlenesharline
Are you able to reproduce the problem every time? Can you narrow down what exactly is necessary to cause this to happen?Progestational
Have you debugged the body before it's sent? Have you tried removing .com to something else to see if the extra '.' still shows? Could be a pattern or escaping sequence of some sort...not sure why though since it's random.Seismism
Perhaps an encoding issue? sounds really odd.Ribaudo
Doing the same test consistently, and the period shows up randomly. The encoding is set to System.Text.ASCIIEncoding @RibaudoUncinate
where do you see the extra period? In your email client? Which client? Maybe check email in gmail web viewer, outlook, etc and compare to see if the viewer is making the changeRaybin
@Raybin currently, i have the SmtpClient writing to a file (DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory). I'm viewing the source/html of the email directly and I see the period. I guess I could try other clients, but I still want to get it working the way it is.Uncinate
I added an update to my question.Uncinate
Seen the update, you may want to save you url into a text file and examine using a hex editor, Notepad++ has a basic plugin for this..your full stop may not be an ASCII representation of a full stop. (single byte, rather than int?)Ribaudo
can you attach image with question so that we can understand how it look like . ? have to tried to open email in different browser?Oeillade
Possible duplicate of System.Net.Mail creating invalid emails and eml files? Inserting extra dots in host namesYuk

© 2022 - 2024 — McMap. All rights reserved.