Mailgun: Sending image using parse cloud code

末鹿安然 提交于 2019-12-23 12:10:47

问题


I have a code defined as

Parse.Cloud.define("mailgunSendMail", function(request, response) {

               var Mailgun = require('mailgun');
               Mailgun.initialize('photoshare.com', 'APPKey');

               Mailgun.sendEmail({
                                 to: "toTestUser@mail.com",
                                 from: "fromTestUser@mail.com",
                                 subject: "Hello from Cloud Code!",
                                 text: "Using Parse and Mailgun is great!",
                                 attachment:"ZXhhbXBsZSBmaWxl"
                                 }, {
                                 success: function(httpResponse) {
                                 console.log(httpResponse);
                                 response.success("Email sent!");
                                 },
                                 error: function(httpResponse) {
                                 console.error(httpResponse);
                                 response.error("Uh oh, something went wrong");
                                 }
                                 });
               });

Mail was sent successfully and recipient got the mail but the attachment is missing. How can i send attachment in the form of data?


回答1:


According to parse, at this point there is no way to send attachments in an email. Check this link

However, if you can include your image file in your HTML code like this if this serves your needs.

html: '<html><body style="text-align:center;"><img border="0" src="http://files.parse.com/6ffa6b80-d0eb-401f-b663-22d4a16df004/bfed9ac4-058c-41fc-a0f1-fb6155572c12-ad77a082-453f-42f7-94ef-40c3f3e885e6.png" alt="Pulpit rock" width="300" height="150"></body></html>'



回答2:


Subash answer is right. I just edited to my question:

Parse.Cloud.define("mailgunSendMail", function(request, response) {
           var Mailgun = require('mailgun');
           Mailgun.initialize('photoshare.com', 'AppKey');

           Mailgun.sendEmail({
                             to: "toTestuser@mail.com",
                             from: "fromTestUser@mail.com",
                             subject: "Hello from Cloud Code!",
                             text: "Using Parse and Mailgun is great!",
                             html: '<html><body><img src="' + request.params.imageUrlKey + '"></body></html>'                                 }, {
                             success: function(httpResponse) {
                             console.log(httpResponse);
                             response.success("Email sent!");
                             },
                             error: function(httpResponse) {
                             console.error(httpResponse);
                             response.error("Uh oh, something went wrong");
                             }
                             });
           });

Where imageUrlKey is a parameter key which contains image url.



来源:https://stackoverflow.com/questions/25161398/mailgun-sending-image-using-parse-cloud-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!