如何通过电子邮件发送屏幕截图?

问题描述 投票:0回答:2

我有一些捕获容器的代码。要捕获,我正在使用“ html2canvas”。我正在尝试通过电子邮件发送此捕获。对于电子邮件,我使用的是“ smtpjs”。我如何通过电子邮件发送捕获?无需保存捕获就可以做到吗?

这是我的代码:

<html>
<head>
    <script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
    <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
    <script src="https://smtpjs.com/v3/smtp.js"></script>
</head>

<body>
<div class="source-container" id="test2" style="background- 
 color:red;width:300px;height:300px;float:left;"></div>

<br/>
<input type='button' id='but_screenshot' value='Take screenshot' onclick='screenshot();'><br/>
<input type='button' id='but_screenshot' value='Send' onclick='email();'><br/>

<!-- Script -->
<script>
    function screenshot() {
        html2canvas(document.querySelector("#test2")).then(canvas => {
            document.body.appendChild(canvas)
        });
    }

    function email() {
        Email.send({
            SecureToken: "0968b-d55-45-b4a8-5d6370",
            To: '[email protected]',
            From: "[email protected]",
            Subject: "This is the subject",
            Body: "iuwaehfiuwreu"
        }).then(
            message => alert(message)
        );
    }
</script>
</body>
</html>
javascript html html2canvas
2个回答
0
投票

从页面https://smtpjs.com/开始

Dev提示:如果您想以base64格式发送附件,传递“路径”作为属性,在dataUri中发送“数据”属性格式。以dataUri格式。 (示例即将推出!)

示例:

Email.send({
    SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
    To : '[email protected]',
    From : "[email protected]",
    Subject : "This is the subject",
    Body : "And this is the body",
    Attachments : [
    {
        name : "smtpjs.png",
        data : canvas.toDataURL()
    }]
}).then(
  message => alert(message)
);

0
投票

smtpjs提供了一种在附件内部发送base64数据的方法。因此,您可以简单地从html2canvas中的base64字节中获取屏幕截图,并通过dataAttachments属性发送数据,如下所示:

Email.send({
    SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
    To : '[email protected]',
    From : "[email protected]",
    Subject : "This is the subject",
    Body : "And this is the body",
    Attachments : [
    {
        name : "smtpjs.png",
        path : "data:image/png;base64,iVBORw0KGgoAAAANSUhEgDz3/Km+vQGsoVNxX="
    }]
}).then(
  message => alert(message)
);

来自smtpjs文档:

Dev提示:如果要以base64格式发送附件,而不是将“ path”作为属性传递,请以dataUri格式发送“ data”属性。以dataUri格式。

© www.soinside.com 2019 - 2024. All rights reserved.