Sending PDF attachments using SMTP function

Hi Everyone,

I’ve looked through this forum but haven’t found an answer to my question so I’m hoping you can help me.

I’m trying to send a PDF file attached to an email which is using HTML to format the text. I’ve tried using the attachment.filename with the name of where the file is stored but all this does is create an email with the body text in the attachment and doesn’t pick up the existing file at all. I’m using stringtobytes function to map the HTML body text into the email content with content type text/html.

Can anyone tell me if this is possible? Or can I only send text email content if attaching anything?

Thanks,

Gill

Gill,

Where are are putting that file to be loaded is it from local c:\drive or it is inside the webMethods/IS installed directory? If so please keep the file inside any of the packages/pub folder or in the main IS/ root itself and hence give the path in the attachments/filename,then smtp service should pick the file and email it accordingly.

HTH,
RMG.

RMG,

The file I’m attaching is stored on the local c drive.

Gill

You should put that file inside the webMethods server root directory,then only the attachment will work.

Please check it out.

Regards,

RMG,

Thanks for your suggestion, however I’ve got it to work now apart from one problem. I need the body text of the email to be html enabled, to do this I create an attachment with contenttype text/html. This works but if I add the pdf attachment all I end up with is a blank email with two attachments, one is a pdf file and the other is a html file. Do you know how I can show the html file in the body of the email?

Thanks,

Gill

Thought people might like to know how I got this to work!

getFile - pulls in the file specified into the body
map - body.bytes to attachment.content with contenttype application/pdf
appendToRecordList - attachments to toList and toList to attachments2 (this supposidly appends the values in toList to the record array)
stringToBytes - body to string, bytes to bytes (this converts the html text inserted into the body text into html code compatible with the attachment.content)
map - bytes to attachment.content, contenttype text/html
appendToRecordList - attachments to fromList, toList to attachments (the first line of the attachments table should be held in toList so after this toList should have 2 entries, if you don’t use attachments2 as a separate field you just overwrite the values)
smtp - attachments to attachments

And hey presto it works, well nearly. As you can see from my above post this code results in a blank email with two attachments. So close…

Gill

Hi Gill,

We have tried pdf attachment.
First generate a PDF by thr following steps
and we were suppose to generate the PDF report

  1.  Prepare XSLT based on the PDF Report layout. 
    
  2.  Pass IS document data in XML format to XSLT to convert to FO format.
    
  3.  Use the FO file to generate the PDF using the pdf:xsltopdf.(custome java service)
    
  4.  Delete the PDF file from the file system after it has been made available to application user.
    

scenarion 1: (without encoding)
Then pass the PDF-content in bytes to attachment.content of the smtp service
set the attachment.contenttype=application/x-pdf

But when we open the attachment in the mail, we get the error saying cannot read the file as file is damaged

Scenario 2 : ( with encoding)
encode the pdf.content in bytes using the pub.string:base64Encode
Then pass this bytes to attachment.content of the smtp service
set the attachment.contenttype=application/x-pdf

But when we open the attachment in the mail, we get the error saying file is not decoded properly.

Please help us on this
Thanks
Sneha

Hi Sneha,

Can you please share the package/code to create the pdf files. I tried to create them but without any success.

If anyone has any built in services that can be used. Can you please go through the steps.

Thank you!

Hi Everyone,

I am new to webMethods and also trying to send an email with a PDF as an attachment. I am using version 9.10.

Any suggestions.

Thanks

Hi Phila,

You need to pass the PDF content to webMethods service (pub.client:smtp) as an attachment and set the content-type as application/pdf.
For more details please have a look at webMethods Integration Server Built-In Services reference guide.

Regards,
Syed Faraz Ahmed

Thanks Syed,

I get a mail with a funny pdf that is unreadable. The body of my email disappears as well.

The pdf is in my local folder.

Regards

Hi Phila ,

1st Option :
Load PDF File as Bytes
Send the bytes via smtp service. In the attachments input map the
bytes to content
set contenttype to “application/pdf”
set encoding to “base64”

one more option is to make use of pub.mime.* services to transform PDF to mime stream and then send it via smtp.
The flow is mentioned below :

pub.file:getFile(load as bytes)
pub.io:bytesToStream(convert bytes to stream)
pub.mime:createMimeData(it will create a mime data , you can add attachment and email body to it)
pub.mime:addBodyPart(pass the pdf stream generated in 2nd step , for pdf mention ContentType: application/pdf;name=“Test.pdf” , encoding base64)
pub.mime:addBodyPart(pass stream of email body[create an stream of string which you want as mail body and use it here],Content-type: text/plain;charset=UTF8 , encoding: quoted-printable )
pub.mime:getEnvelopeStream(form mime stream)
pub.client:smtp(send it via smtp)

You will get an email with attached PDF and text. In a single instance of mime data you can attach multiple files as well as mail body.

1 Like

Thanks Rakesh for feedback.

I configured as advised and now getting the error below.

Can you please help.

Thanks

Regards
Phila

Could not run ‘sendEmail_1’
java.lang.ClassCastException: com.wm.util.Values cannot be cast to java.lang.String

java.lang.ClassCastException: com.wm.util.Values cannot be cast to java.lang.String
at pub.clientimpl.smtp(clientimpl.java:354)
at sun.reflect.GeneratedMethodAccessor284.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:406)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:650)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:39)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:49)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:243)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:171)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:303)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:34)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:377)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:549)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:386)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:238)
at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:221)
at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:254)
at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:520)
at com.wm.lang.flow.FlowState.step(FlowState.java:389)
at com.wm.lang.flow.FlowState.invoke(FlowState.java:360)
at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:1052)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:650)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:39)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:49)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:243)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:171)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:303)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:34)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:377)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:549)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:386)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:238)
at com.wm.app.b2b.server.comm.DefaultServerRequestHandler.handleMessage(DefaultServerRequestHandler.java:119)
at com.wm.app.b2b.server.HTTPMessageHandler.process(HTTPMessageHandler.java:156)
at com.wm.app.b2b.server.HTTPDispatch.handleRequest(HTTPDispatch.java:170)
at com.wm.app.b2b.server.Dispatch.run(Dispatch.java:365)
at com.wm.util.pool.PooledThread.run(PooledThread.java:127)
at java.lang.Thread.run(Thread.java:745)

Launch completed: 2017-03-02 16:05:55.889

Hi Phila ,

I believe you used 1st approach , this error comes because of body input parameter of “pub.client:smtp” is a required parameter and you have not set any value to it. Set some value for body or map some data then try.

I assigned some value to the body as advised and It is now working.

Thanks a lot for the help.

Regards
Phila

Hi Phila ,

Thanks for updating back.