Mailto with Subject and Body in Blazor

Viewed 374

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:m.mustermann@domain.de?subject=Test%20Test%20Test%20Test&amp;body=Test%20Test,%0D%0A%0D%0ATest%20Test%20Test%20Test.">Test</a>

        <a href="mailto:?subject=MessageCode: @ErrorCode %20&amp;body=Test%20Test,%0D%0A%0D%0AURL: @navigationManager.Uri">Send Mail</a>
1 Answers

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

This works:

<a href="mailto:?subject=MessageCode%3A @ErrorCode Test&body=Test%20Test,%0D%0A%0D%0AURL%3A @MyUrl">Send Mail</a>

with

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

Also note the %3A 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 %20@ErrorCode does not work.

Related