Home > database >  Mailto with Subject and Body in Blazor
Mailto with Subject and Body in Blazor

Time:11-13

I would like to send a mail with variables. The first snippet is a raw HTML mailto text, the other one is my solution.

The problem is that then the body of the mail is no longer generated.

<a href="mailto:[email protected]?subject=Test Test Test Test&amp;body=Test Test,

Test Test Test Test.">Test</a>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

        <a href="mailto:?subject=MessageCode: @ErrorCode  &amp;body=Test Test,

URL: @navigationManager.Uri">Send Mail</a>

CodePudding user response:

Everything in the mailto: has to be Url encoded. Especially the URL from navigationManager.

This works:

<a href="mailto:?subject=MessageCode: @ErrorCode Test&body=Test Test,

URL: @MyUrl">Send Mail</a>

with

string MyUrl => System.Web.HttpUtility.UrlEncode(navigationManager.Uri);

Also note the : instead of :

When your @ErrorCode can have punctuation in it then give it the same treatment.

It is a good thing that space are allowed because @ErrorCode does not work.

  • Related