smpt email PDF file

I have a requirement where i need to get PDF file from window folder directory and attach PDF file in email and send to customer.

I am able to attach pdf file in email and able to send to customer but when i open attached PDF file it’s show error message as below

"Adobe Acrobat Reader DC could not open ‘xyz.pdf’ because it is either not a support file type or because file has been damage(for example it was send as a email attachment and wasn’t correct decoded)

code logic

  1. get file as string
    2 pass string to decode public folder built in service
    3 attached pdf file via smtp

But still i am able to see above error message when i open PDF attachment.

Do any one has handle such scenario before or let me know where i am missing ?

Hello Vinay,

You should read PDF file as stream but not as string. Because this is not a CSV or XML file to read as String.

Map the stream to attachment steam object, give a name for the attachment and set content type.

Hope this helps.

Regards,
Srikanth

Please do remember you have to use attachments document list of pub.client:smtp service, one document of attachments list should be having the body and another should be with the file stream.

while i am doing load as stream and i am able to send email with attachement but still i am unable to view attachment properly

Questions :-

  1. How ll i know what is the encoding coming in PDF file content?
    Is there any way to extract encoding?

  2. As we pass it load as stream then Is there any way we can find out encoding of stream ?

  3. how to decode stream ?

I have tried to used pub.string.Decodebase64 but input of this service is string and when i tried to convert stream to string again it has same issue.

Is there any way to decode stream

  1. get file list from directory
  2. loop over file list
  3. pub.get.file (file name & load as stream) here i can see it coming as java.io.BufferedInputStream
  4. Map (file name, value to content , content type application/pdf)
  5. Map append
  6. pub.client.smtp (set all required mandatory fields and even set attachment fields with encoding & charset UTF-8)
    I have tried removing encoding & charset but still no luck.

how to handle this ?

com.wm.app.b2b.server.ServiceException: javax.mail.MessagingException: IOException while sending message;

nested exception is:
java.io.UnsupportedEncodingException: WinAnsiEncoding
at pub.clientimpl.smtp(clientimpl.java:666)

Hello Vinay,

I have just tried this and it works fine. Please do the below.

1.pub.file:getFile as bytes with base64 encoding
2. pub.client:smtp with content, content type, file name and encoding.

Regards,
Srikanth

Srikanth,

In beginning itself i told I am able to handle this PDF but while reading pdf which received via email is not working due to encoding problem.

I have tried with base64 encoding it’s partially work i can see color in PDF but not able to view it proper image or text written over there so still something is missing here over here

I can’t able to share PDF file which i am testing due to some restriction but i can say it’s has color image or scan copy of product with text for example it may be anything like scan color copy of mobile phone with text in pdf

it’s coming with unsupported encoding i believe.

<</Type/Font/Subtype/TrueType/Name/F1/BaseFont/ABCDEE+Calibri/Encoding/WinAnsiEncoding/FontDescriptor 6 0 R/FirstChar 32/LastChar 32/Widths 17 0 R>>
endobj

Thanks for your support

Perfect Issue resolved.

1.pub.file:getFile as bytes with base64 encoding
2. pub.client:smtp with content, content type, file name and encoding.

In point 2 smtp service i am not providing encoding type # base64
as per SAG documentation it’s using default encoding which creating issue while sending PDF file in attachment.

but still i have questions … what ever may be file or content type how ll i know what is the encoding or current file ?

Is there any way to figure it out.

Since the use case is to just to attach file to email, we really does not need to know the encoding. This can be base64 for all the file types. We just need to know the content type which we will come to know while reading the file.