I have a class that uses a razor mechanism to generate html templates, and it seems that the problem is that some links (links or images) have an extra period inserted in the address, usually on www. part makes the connection unusable.
It seems that there is no rhyme or reason as to when and where this happens, sometimes it works fine, while some of the links have this problem.
Therefore, when I return the template as a string and then send it as a letter, I call a replacement, as shown below:
var fixedTemplate = template.Replace("www..", "www.");
But that does not work. I have never encountered this problem before. The strings are quite large, can this cause problems with the replace function?
How can I
a) Fasten the razor motor so that these random periods are no longer added to the links
or
b) Find out why replace does not replace all occurrences.
Sample code in my class below for completeness.
using (TemplateService templateService = new TemplateService())
{
string html = templateService.Parse(File.ReadAllText(nt.TemplateFilePath), nt, null, null);
var pm = new PreMailer.Net.PreMailer(html);
Emailer.SendTestEmail(pm.MoveCssInline().Html, emailAddress, "Test Email: " + campaign.Title);
pm = null;
}
And the sender code in which the replacement is called
public static void SendTestEmail(string template, string emailAddress, string subject)
{
var updatedTemplate = template.Replace("www..", "www.");
var email = new MailMessage
{
Body = updatedTemplate,
Subject = subject,
IsBodyHtml = true,
From = new MailAddress("noreply@mydomain.com")
};
email.To.Add(emailAddress);
using (var smtpClient = new SmtpClient())
{
smtpClient.PickupDirectoryLocation = "M:\\Pickup";
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpClient.Send(email);
}
}