andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 169 forks source link

Problem sender mail #120

Open matteoventuri7 opened 9 years ago

matteoventuri7 commented 9 years ago

Hi, in my project (MVC5 and Postal.Mvc5 1.2.0) i try to send mail with sender e-mail like "Mike Jones <mike@jones.com>" (without quotes) and when e-mail start I receive this error: The message header contains an invalid character ';'.

Thanks.

iamgurdip commented 8 years ago

I had the same issue, problem is that Razor Engine parser Html encodes the string, so your email address would end up as Mike Jones &lt;mike@jones.com&gt; which is invalid email address. I was able to fix it by implementing my own IEmailParser. Basically copy the EmailParser and change the following in AssignEmailHeaderToMailMessage

case "to":
     message.To.Add(value);
     break; 

to


case "to":
    value = HttpUtility.HtmlDecode(value);
    message.To.Add(value);
    break;