postal icon indicating copy to clipboard operation
postal copied to clipboard

Chokes on "<" and ">" in headers

Open migig opened this issue 10 years ago • 5 comments

I understand that a Postal from, sender, to, cc, bcc field should look like this: Foo Bar [email protected].

We use the MailAddress class for all sorts of stuff, and so I already have the email database in that format, and when I call mymailaddress.ToString() you get Foo Bar <[email protected]>. Which is all OK.

But those angle brackets cause Postal to choke, because when it puts those strings into a new MailAddress, you get an exception.

Is there some easy way to avoid this? Ideally, somewhere in the parsing there should be something like somestring.Replace("<","").Replace(">",""). Does Postal check for this? If not, it probably should because that is the standard header format.

I can send a PR if you give me a clue where in the code to make this change.

migig avatar Feb 21 '15 12:02 migig

I have no problems using angle brackets in headers. However, the Razor view itself chokes on them, unless you take precautions. Perhaps that's what your issue is?

Anyways, this is all I do:

@Html.Raw("<[email protected]>")

If your var already has the angle brackets embedded in the string, just do:

@Html.Raw(myEmailVar)

chrisdpratt avatar Aug 06 '15 20:08 chrisdpratt

any update on this? Html.Raw isnt working for me

chrissmillie avatar Feb 07 '16 22:02 chrissmillie

I'm still using this successfully in production. If Html.Raw isn't working for you there's some other issue at play. Can you provide any more detail as to how it's not working for you, including any exceptions and stacktraces?

chrisdpratt avatar Feb 08 '16 16:02 chrisdpratt

I was having an issue with < > choking in the template too. When I went to use @Html.Raw I found that the call wouldn't work when using Postal outside of ASP.Net. I fixed this by using a RawString call instead of Html.Raw:

From: @(new RazorEngine.Text.RawString(Model.From))

jonmabe avatar Apr 15 '16 19:04 jonmabe

The only thing that work form me is to remove the < and > from the Model.From

Drakkins avatar May 15 '17 15:05 Drakkins