mailto link with HTML body

前端 未结 10 1863
攒了一身酷
攒了一身酷 2020-11-21 22:26

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


Can I insert HTML formatted body in the <

相关标签:
10条回答
  • 2020-11-21 23:13

    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>                        
    
    0 讨论(0)
  • 2020-11-21 23:18

    It's not quite what you want, but it's possible using modern javascript to create an EML file on the client and stream that to the user's file system, which should open a rich email containing HTML in their mail program, such as Outlook:

    https://stackoverflow.com/a/27971771/8595398

    Here's a jsfiddle of an email containing images and tables: https://jsfiddle.net/seanodotcom/yd1n8Lfh/

    HTML

    <!-- https://jsfiddle.net/seanodotcom/yd1n8Lfh -->
    <textarea id="textbox" style="width: 300px; height: 600px;">
    To: User <user@domain.demo>
    Subject: Subject
    X-Unsent: 1
    Content-Type: text/html
    
    <html>
    <head>
    <style>
        body, html, table {
            font-family: Calibri, Arial, sans-serif;
        }
        .pastdue { color: crimson; }
        table {
            border: 1px solid silver;
            padding: 6px;
        }
        thead {
            text-align: center;
            font-size: 1.2em;
            color: navy;
            background-color: silver;
            font-weight: bold;
        }
        tbody td {
            text-align: center;
        }
    </style>
    </head>
    <body>
    <table width=100%>
        <tr>
            <td><img src="http://www.laurell.com/images/logo/laurell_logo_storefront.jpg" width="200" height="57" alt=""></td>
            <td align="right"><h1><span class="pastdue">PAST DUE</span> INVOICE</h1></td>
        </tr>
    </table>
    <table width=100%>
        <thead>
            <th>Invoice #</th>
            <th>Days Overdue</th>
            <th>Amount Owed</th>
        </thead>
        <tbody>
        <tr>
            <td>OU812</td>
            <td>9</td>
            <td>$4395.00</td>
        </tr>
        <tr>
            <td>OU812</td>
            <td>9</td>
            <td>$4395.00</td>
        </tr>
        <tr>
            <td>OU812</td>
            <td>9</td>
            <td>$4395.00</td>
        </tr>
        </tbody>
    </table>
    </body>
    </html>
    </textarea> <br>
    <button id="create">Create file</button><br><br>
    <a download="message.eml" id="downloadlink" style="display: none">Download</a>
    

    Javascript

    (function () {
    var textFile = null,
      makeTextFile = function (text) {
        var data = new Blob([text], {type: 'text/plain'});
        if (textFile !== null) {
          window.URL.revokeObjectURL(textFile);
        }
        textFile = window.URL.createObjectURL(data);
        return textFile;
      };
    
      var create = document.getElementById('create'),
        textbox = document.getElementById('textbox');
      create.addEventListener('click', function () {
        var link = document.getElementById('downloadlink');
        link.href = makeTextFile(textbox.value);
        link.style.display = 'block';
      }, false);
    })();
    
    0 讨论(0)
  • 2020-11-21 23:20

    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;
    
    0 讨论(0)
  • 2020-11-21 23:22

    I have same issue regarding sharing html. I do below html work for me. Replace < with < & > with >.

    <a href="mailto:?subject=link Share&body=&lt;a href='www.google.com'&gt;google&lt;/a&gt;">Email</a>

    Note: It work only in ubuntu. It will not work in windows.

    0 讨论(0)
提交回复
热议问题