Unable to send mail with attachment using smtp_send_mail


We have a requirement to trigger emails with PDF document as attachment.

I am using SMTP functions (smtp_send_mail) with the below code, but the mail is sent without the attachment:

If someone has used this function, please let me know what I am doing wrong in my case.


// ---------------SMTP Send Mail------------

    smtp_send_mail( "SendMail",







            "X–Priority: 3",

            "X–MSMail–Priority: Normal",

            "X–Mailer: Microsoft Outlook Express",

            "X–MieOLE: Produced By Microsoft MimeOLE V5.00.2919.6700",


            "MessageText=This is a case mail\r\n",


        LAST );


Parents Reply Children
  • Did you follow the three above links, examine the content and translated the example into your LR-script?

    If you still have issues you might share your effort, others might help you further.

  • smtp_send_mail("SendMail",

            LAST );

    I am unable to set the boundary. Do i need to encode the pdf?

  • The LR help it self suggests that you needt to specify after MAILDATA patterns like "LR-TAG=<data>", but it is not very clear about encoding and now to specify e.g a boundary.

    Note that some values need to be put between quotes, like boundary="BoundaryForAttachment" and name="Test_200KB.pdf" so you need to escape the quotes in your C-string.

    Also e-mail / smtp tags-value pairs are not using = but are using :, This applies to your Content-Type and Content-Disposition.

  • I liked your question, so  I played a little with the API, full logging, wireshark. I learned:

    - LR it self takes care of the boundaries, by default the ContentType=multipart/mixed

    - It looks like MessageBlob=... does not work.

    - I encoded a pdf as base64, saved the file in my LR-script folder and added at the top of the file: Content-Type, Content-Transfer-Encoding, Content-Disposition.

    - I do not see a From in gmail when I received the message (error in LR (?), because it is sending 'MAIL FROM: user@x.com', note the space afer the :

    - The attachement is nicely visable in gmail.

    - Each argument after MAILDATA gets its own boundary, argument can be repeated.

    So here is my code:

    	               , "To=xxx@gmail.com"
    	               , "Subject=Test"
    	               , "From=xxx@microfocus.com"
    	               , MAILDATA
    	               , "MessageText=Please see attachment YTD.pdf"
    	               , "AttachRawFile=YTD.txt"

    Here is the top of my YTD.txt file with the boundary-headers:



    An alternative way is to store the base64 encoded file in a buffer:

    char *YTDPDF =
    	               , "To=xxx@gmail.com"
    	               , "Subject=Test"
    	               , "From=xxx@microfocus.com"
    	               , MAILDATA
    	               , "MessageText=Please see attachment YTD.pdf"
    	               , YTDPDF



  • Oh yes. This way it works :)  I am able to attach multiple files using AttachRawFile command required number of tiimes. I have used the function smtp_translate to perform the encoding. Also seems like the Message_Text not working while using AttachRawFile command. To create a body text i have attached another raw file and mentioned content_disposition as inline.

    Thanks for your help Remmelzwaal .Cheers.


  • I am able to send mail successfully and could see attachment in the mail if i use the vugen. But if i try to execute the same script in performance centre , suject is not appearing , everything comes as a inline text of body. any suggestions for that?

    Date: Thu, 14 Jun 2018 10:42:17 0000

    Subject: TestMail

    MIME-Version: 1.0




    This is a multi-part message in MIME format.









    cnVlPj4 Pg0KZW5kb2JqDQoyIDAgb2JqDQo8PC9UeXBlL1BhZ2VzL0NvdW50IDExL0tpZHNb




  • I would suggest to make a new thread for this issue (or moderators can do this for you).

    Did you try 1 user in PC or multiple users. When multiple you might run into concurrent file generation, due to smpt_translate()  function; try 1 user first.