Skip to Content
avatar image
Former Member

sending mail with images via xsjs

Hi,

I am using SMTP relay server to send mails via XSJS project. I am able to send mails with HTML content and normal text type. However now i also want to embed images in the mails. I am using typical HTML format <img width=500 height=100 src=cid:Capture>", however it is not working.When the mail is received there is error shown in space of image : The linked image cannot be displayed.

Any pointers on how to send mails using xsjs using HTML content with embedded images.

Add comment
10|10000 characters needed characters exceeded

  • Please can you share how to create the parts of the mail (the image file part and the html part).

    Thx,
    Florian

  • Former Member Florian Pfeffer

    Below is the HTML content of the mail with the image embedded :

    var mailContent = "<html><body><img width=500 height=100 src=cid:Capture.PNG><p>Test email,</p> </body></html>";<I have placed the image with name Capture.png in the XS project folder directly>

    Below is the code for sending the mail :

    // Create an attachment $.net.Mail.Part from JSObject.

    var Attachment = new $.net.Mail.Part({ type: $.net.Mail.Part.TYPE_ATTACHMENT,

    data: <Here i have converted the image into binary format which is long queues of 0s and 1s and passing as string>

    contentType: "image/png",

    fileName: "Capture.PNG",

    fileNameEncoding: "UTF-8" });

    var HTMLContent= new $.net.Mail.Part();

    HTMLContent.type = $.net.Mail.Part.TYPE_TEXT;

    HTMLContent.text = bodyContent;

    HTMLContent.contentType = "text/html";

    HTMLContent.encoding = "UTF-8";

    var mail = new $.net.Mail({ sender: {address: "namrata.dixit@xyz.com"}, to: [{ address: "abc@xys.com}], subject: mainContent, subjectEncoding: "UTF-8" }); mail.parts.push(Attachment,HTMLContent);

    Regards,

    Namrata

  • Get RSS Feed

1 Answer

  • May 05, 2017 at 09:59 AM

    Instead of an attachment you should create an mail part of type $.net.Mail.Part.TYPE_INLINE in which you can define the Content ID you refer in the HTML part.

    You can check the example in the documentation: https://help.sap.com/http.svc/rc/3de842783af24336b6305a3c0223a369/2.0.01/en-US/$.net.Mail.Part.html

    Please enclose the value of the image src attribute also in double quotes to avoid any issues (e.g. src="cid:CAPUTURE"). Of course you need to adjust the value to contain the defined content id in the inline part.

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded