javascript - 使用 Angular 和 Mandrill 通过电子邮件发送带有附件的表单结果

标签 javascript angularjs forms mandrill

我有一个带 Angular 表单句柄,用户可以为其应用程序填充该句柄。 它工作正常,我使用 Mandrill API 发送电子邮件,如下所示:

var m = new mandrill.Mandrill('your_api_key'); // This will be public

function sendTheMail(){
    m.messages.send({
        "message": {
            "from_email": "your_email_address",
            "from_name": "your_name",
            "to":[{"email": "someone's_email_address", "name": "someone's_name"}], // Array of recipients
            "subject": "optional_subject_line",
            "text": "Text to be sent in the body" // Alternatively, use the "html" key to send HTML emails rather than plaintext
        }
    });
}

现在我想让用户能够将 pdf 附件添加到他们的应用程序中。我可以将格式限制为PDF,并且尺寸相对较小。

最简单的方法是什么?我需要添加像 https://github.com/nervgh/angular-file-upload 这样的模块吗? ?

非常感谢

最佳答案

在消息 Json 中输入附件,它是一个数组,您可以添加更多附件。附件哈希中的字段为“type”(字符串)=>附件的 MIME 类型,“name”(字符串)=>附件的文件名,“content”(字符串)=>作为附件的内容Base64 编码的字符串。

"attachments": [
        {
            "type": "text/plain",
            "name": "myfile.txt",
            "content": "ZXhhbXBsZSBmaWxl"
        }
    ]

关于javascript - 使用 Angular 和 Mandrill 通过电子邮件发送带有附件的表单结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37958264/

相关文章:

Javascript:定义一个新的原型(prototype),它将用 document.findId() 替换 document.getElementById()

javascript - 无法在 Angular 上正确加载消息

javascript - 使用 jquery 单击时,html 中的 li 标记不显示任何操作

javascript - Angular - ng-repeat 不适用于搜索 Controller

javascript - Angular .min.js :118 Error: [ng:areq]

javascript - 防止在输入 VueJS/Semantic UI 时提交表单

javascript - 如何使用单选按钮过滤 jQuery 中的元素

c# - 透明表单无法正确显示文本

javascript - 当特定的 ajax 请求完成时做某事

javascript - dygraphs 图例中的形状