Sending Email with Attachment

Hi Team,

I need to send PDF file as attachment through email. I am able to send it using pub.cleant:SMTP service. However when I try to open that PDF file it gives error file is not decoded properly. I am passing htmlmailStream as input to the pub.cleant:SMTP. htmlmailStream is obtained from the output of pub.mime:getEnvelopeStream.

Can you please suggest hot to resolve it.

Thanks &Regards,
NB

Could you try passing it base64encoded and while receiving it base64decoded? Use the built in services for base64 encoding and decoding.

Regards
Senthil

What is the content-type you are specifying in the smtp service under data/ or attachments and make sure it is application/PDF and also try with base64 encode/decode as Senthill suggested above.

HTH,
RMG

Hi Senthilkumar,

Thanks for guidance.

While sending, I will encode it. I am not clear about decoding. Once I received this pdf in email after that I do not want any thing to do. It should open as expected. This is our requirement. Can you please make me more clear on when should I decode the content.

Hi,

Please decode the encoded input ,pass that byte value to the content and use base 64 in encoding in attachments document in smtp service.

emailAttachment.PNG

Hi Sathyaraj

Still, I am getting the same error. Below is the flow of my code.

  1. I invoked pub.mime:getEnvelopeStream service. It’s output is a stream.
  2. Converted this stream into bytes.
  3. encoded bytes into base64 using service pub.string:base64Encode. It’s output is a string.
  4. Here I am invoking service pub.client:smtp. In attachements\conten, I passed this encoded string, contentType set to application/pdf, file name set to test.pdf and encoding set to base64.

Could you please let me know where I should try to decode it. I tried to decode it using 2-3 scenarios but still getting the same error.

Thanks in advance…!!

Hi,

Please use the attached sample package which I got from the forum.

Let us know if thats what you needed?

Thanks,
Sathya
HTMLEmailWithAttachment.zip (6.91 KB)

Hi NB,

I am having the same issue as you had while opening the PDF.

Could you please share how you resolved the issue?

Regards,
Irfan

I am facing the same issue,Did you resolve this?