【问题标题】:Send a form result with attachment via email using Angular and Mandrill使用 Angular 和 Mandrill 通过电子邮件发送带有附件的表单结果
【发布时间】:2016-10-23 19:39:14
【问题描述】:

我有一个用户为其应用程序填充的带有角度的表单句柄。 它工作正常,我使用 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 之类的模块?

非常感谢

【问题讨论】:

标签: javascript angularjs forms mandrill


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-07-04
    • 2015-07-11
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多