Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

XSJS - Unable to send mail with pdf attachment

$
0
0

Hi All,

 

Requirement : Send across the html content (google map and its directions) in mail to end users.

 

I am trying send the current html content as pdf attachment (snapshot of existing html) to xsjs which has to send mail with pdf attachment when i click on a button in the html.

 

I am using jspdf and html2canvas to generate the pdf. Please let me know where i am going wrong?

 

Note: 1. I was able to send simple mail without attachment using ajax and xsjs.


         2. I am using Hana SPS 09 version and developing it in sap hana cloud web ide

 

HTML code : On click of a button, i call the below function to generate pdf of the html content (google map and its directions).

 

        $(function() {

            $('.arrow-right').click(function(event) {

                alert('Inside screenshot');

                var data = "";

                var pdf = new jsPDF('p', 'pt', 'a4');

                pdf.setFontSize(40);

                var options = {

                    pagesplit: true

                };

 

                pdf.addHTML($(".sapUiBody"), options, function() {

                 //   pdf.save("Services/test.pdf");

                 // pdf.output('datauri');

                  data = pdf.output();

                  console.log(data);

                });

                $.ajax({

                 url: 'Services/EmailAttachment.xsjs',

                 type: 'POST',

                 data: data,

                 success:function(){},

                 error:function(jqXHR, textStatus, errorThrown){

                     sap.ui.commons.MessageBox.show(jqXHR.responseText, "ERROR", "Service call error");

                 }

             });

            });

        });

 

EmailAttachment.xsjs

 

var pdfDoc = $.request.entities[0].body.asString();

var mail = new $.net.Mail({

sender: {address: "abc@xxx.com"},

to: [{ address: "abc@xxx.com"}],

subject: "XSJS Email Test",

parts: [ new $.net.Mail.Part({

type: $.net.Mail.Part.TYPE_TEXT,

text:"Attachment Test",

contentType: "text/plain"

})]

});

mail.parts.push(new $.net.Mail.Part({

type: $.net.Mail.Part.TYPE_ATTACHMENT,

data: pdfDoc,

contentType: "application/pdf",

fileName: "Test.pdf"}));

var returnValue = mail.send();

 

Thanks,

Priya


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>