mailto link with HTML body

2018-12-31 03:14发布

I have a couple of mailto links in a HTML document.

<a href="mailto:etc...">

Can I insert HTML formatted body in the mailto: part of the href?

<a href="mailto:me@me.com?subject=Me&body=<b>ME</b>">Mail me</a>

Note that (2016) in iOS, it is perfectly fine to add <i> and <b> tags for simple italic, bold formatting.

10条回答
残风、尘缘若梦
2楼-- · 2018-12-31 03:35

I have used this and it seems to work with outlook, not using html but you can format the text with line breaks at least when the body is added as output.

<a href="mailto:email@address.com?subject=Hello world&body=Line one%0DLine two">Email me</a>
查看更多
笑指拈花
3楼-- · 2018-12-31 03:36

No. This is not possible at all.

查看更多
一个人的天荒地老
4楼-- · 2018-12-31 03:37

Whilst it is NOT possible to use HTML to format your email body you can add line breaks as has been previously suggested.

If you are able to use javascript then "encodeURIComponent()" might be of use like below...

var formattedBody = "FirstLine \n Second Line \n Third Line";
var mailToLink = "mailto:x@y.com?body=" + encodeURIComponent(formattedBody);
window.location.href = mailToLink;
查看更多
孤独总比滥情好
5楼-- · 2018-12-31 03:37

Some things are possible, but not all, say for example you want line breaks, instead of using <br />use %0D%0A

Example:

<a href="mailto:?subject=&body=Hello,%0D%0A%0D%0AHere is the link to the PDF Brochure.%0D%0A%0D%0ATo view the brochure please click the following link: http://www.uyslist.com/yachts/brochure.pdf"><img src="images/email.png" alt="EMail PDF Brochure" /></a>                        
查看更多
浮光初槿花落
6楼-- · 2018-12-31 03:37

It is possible to enter unicode values to insert newlines (ie: \u0009) but HTML tags have varying degrees of support and should be avoided.

查看更多
几人难应
7楼-- · 2018-12-31 03:38

Here's how you add everything to a MAILTO link:

<a href="mailto:YourName@YourSite.com? cc=someone@YourSite.com&bcc=someoneElse@YourSite.com &subject=Shipping%20Information%20Request&body=Please%20tell%20me%20if%20my%20order%20has%20shipped!">Shipping Request</a>

Each component is separated by the ampersand (&) sign. Only the first component after the initial email address has a question mark (?) preceding the ampersand.

URL-encode is the key! So for your example of a body, instead of your

href='mailto:me@me.com?subject=Me&body=<b>ME</b>'

...you might try:

href='mailto:me@me.com?subject=Me&body=%3cb%3eME%3c%2fb%3e'

Here's another route you might try. Create a javascript function to open an ActiveX object. This has the unfortunate limitation of only working in IE and Outlook, and may cause your page to show activex warnings. But if you can live with these caveats, it does the job. Here's a working sample you can draw from:

<html>
    <head>
        <script type='text/javascript' language='javascript'>
            function OpenOutlookNewEmail()
            {
                try
                {
                    var outlookApp = new ActiveXObject("Outlook.Application");
                    var nameSpace = outlookApp.getNameSpace("MAPI");
                    mailFolder = nameSpace.getDefaultFolder(6);
                    mailItem = mailFolder.Items.add('IPM.Note.FormA');
                    mailItem.Subject = "Me";
                    mailItem.To = "me@me.com";
                    mailItem.HTMLBody = "<b>ME</b>";
                    mailItem.display(0);
                }
                catch (e)
                {
                    alert(e);
                    // act on any error that you get
                }
            }
        </script>
    </head>
    <body>
        <a href='javascript:OpenOutlookNewEmail()' >email</a>
    </body>
</html>
查看更多
登录 后发表回答