Highlighted
Trusted Contributor.
Trusted Contributor.
2836 views

Unable to send mail with attachment using smtp_send_mail

Jump to solution

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 );

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Hi

I believe you have some headers missing in your SMTP.

content type for pdf is "application/pdf". Also, I'd use the "Content-Type:multipart/mixed" for the entire message.

In short, please review the proper SMTP structure and try again

Try this link as a reference and also this link (and this as wel :-))

Good Luck,

Lior

View solution in original post

0 Likes
10 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Hi

I believe you have some headers missing in your SMTP.

content type for pdf is "application/pdf". Also, I'd use the "Content-Type:multipart/mixed" for the entire message.

In short, please review the proper SMTP structure and try again

Try this link as a reference and also this link (and this as wel :-))

Good Luck,

Lior

View solution in original post

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Thanks for your response, it is working now.

0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

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

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

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.

Signature:
Reward community members who take time to respond and help.
0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

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?

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

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.

Signature:
Reward community members who take time to respond and help.
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

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
	              );
	...

 

 

Signature:
Reward community members who take time to respond and help.
Highlighted
Frequent Contributor.
Frequent Contributor.

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.

 

0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

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

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

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

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.

 

Signature:
Reward community members who take time to respond and help.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.