简体   繁体   English

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

[英]Send a form result with attachment via email using Angular and Mandrill

I have a form handle with angular that users populate for their application. 我有一个带有角度的表单句柄,用户填充它们的应用程序。 It works fine, I use the Mandrill API to send the e-mail like this: 它工作正常,我使用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
        }
    });
}

Now I'd like to enable users to add a pdf attachment to their application. 现在我想让用户在他们的应用程序中添加pdf附件。 I can limit the format to PDF and the size to be relatively small. 我可以将格式限制为PDF,尺寸相对较小。

What is the simplest way to do so? 最简单的方法是什么? Do I need to add a module like https://github.com/nervgh/angular-file-upload ? 我是否需要添加https://github.com/nervgh/angular-file-upload等模块?

Many thanks 非常感谢

make entry for attachments in your message Json , it's an array you can add more attachments. 在您的消息Json中输入附件,这是一个可以添加更多附件的数组。 fields in attachments hash are "type"(string)=>the MIME type of the attachment, "name"(string)=>the file name of the attachment, "content"(string)=>the content of the attachment as a base64-encoded string. 附件哈希中的字段是“type”(字符串)=>附件的MIME类型,“name”(字符串)=>附件的文件名,“content”(字符串)=>附件的内容为base64编码的字符串。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM