Unable to send mail with attachment using smtp_send_mail

Hi,

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",

         "To=xx@xxx.com",

        "From=xx@xxx.com",

        "Subject={Subject}",

        "ContentType=text/plain;",

        "charset=\"iso–8859–4\"",

        MAILOPTIONS,

            "X–Priority: 3",

            "X–MSMail–Priority: Normal",

            "X–Mailer: Microsoft Outlook Express 10.31.88.237",

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

        MAILDATA,

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

            "File=Closure.PDF",

        LAST );

 

Parents Reply Children
  • Hi , I am facing issue in attaching PDF in SMTP protocol. Could you please provide some example?

  • 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",
            "To=xxxxx@yyyyy.com",
            "From=xxxxx@yyyyy.com",
            "Subject=TestMail",
            "ContentType=multipart/mixed;boundary=BoundaryForAttachment",
     "Content-Disposition=attachment;",
            MAILOPTIONS,

            MAILDATA,
               "--BoundaryForAttachment",
                "ContentType=application/pdf;name=Test_200KB.pdf",
                "File=Test_200KB.pdf",
     "--BoundaryForAttachment--",
            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:

    	smtp_send_mail("mail"
    	               , "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:

    Content-Type:application/octet-stream;name="YTD.pdf"
    Content-Transfer-Encoding:base64
    Content-Disposition:attachment;filename="YTD.pdf"
    JVBERi0xLjUKJcfsj6IKNCAwIG9iago8PC9MaW5lYXJpemVkIDEvTCA0MDc3MC9IWyAzODEzMyAx
    NDFdL08gNi9FIDM4MTMzL04gMS9UIDQwNjQ5Pj4KZW5kb2JqCiAgICAgICAgICAgICAgICAgICAg
    ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAp4cmVmCjQgMjEKMDAwMDAwMDAxNSAwMDAw
    MCBuIAowMDAwMDAwNzI4IDAwMDAwIG4gCjAwMDAwMDA4NzMgMDAwMDAgbiAKMDAwMDAwMTAzMyAw
    MDAwMCBuIAowMDAwMDA0MTU0IDAwMDAwIG4gCjAwMDAwMDQxNzQgMDAwMDAgbiAKMDAwMDAwNDIx
    ...

     

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

    char *YTDPDF =
    	"MessageText="
    "Content-Type:application/octet-stream;name=\"YTD.pdf\"\n"
    "Content-Transfer-Encoding:base64\n"
    "Content-Disposition:attachment;filename=\"YTD.pdf\"\n"
    "JVBERi0xLjUKJcfsj6IKNCAwIG9iago8PC9MaW5lYXJpemVkIDEvTCA0MDc3MC9IWyAzODEzMyAx\n"
    "NDFdL08gNi9FIDM4MTMzL04gMS9UIDQwNjQ5Pj4KZW5kb2JqCiAgICAgICAgICAgICAgICAgICAg\n"
    "ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAp4cmVmCjQgMjEKMDAwMDAwMDAxNSAwMDAw\n"
    "MCBuIAowMDAwMDAwNzI4IDAwMDAwIG4gCjAwMDAwMDA4NzMgMDAwMDAgbiAKMDAwMDAwMTAzMyAw\n"
    ....
    ;
    
    Action()
    {
    	...
    	smtp_send_mail("mail"
    	               , "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

    Content-Type:multipart/mixed;

                    boundary="------=_NextPart_00000003_00000406.01790D48"

     

    This is a multi-part message in MIME format.

     

    --------=_NextPart_00000003_00000406.01790D48

    Content-Type:application/pdf;name="1MB.pdf"

    Content-Transfer-Encoding:base64

    Content-Disposition:attachment;filename="1MB.pdf"

     

    JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIv

    TGFuZyhlbi1HQikgL1N0cnVjdFRyZWVSb290IDQzIDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0

    cnVlPj4 Pg0KZW5kb2JqDQoyIDAgb2JqDQo8PC9UeXBlL1BhZ2VzL0NvdW50IDExL0tpZHNb

    IDMgMCBSIDEyIDAgUiAxNSAwIFIgMTggMCBSIDIxIDAgUiAyNCAwIFIgMjcgMCBSIDMwIDAg

    UiAzMyAwIFIgMzUgMCBSIDM4IDAgUl0gPj4NCmVuZG9iag0KMyAwIG9iag0KPDwvVHlwZS9Q

    .............................................

  • 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.