unable to attach text file in HTML email

Hi all,

I have created a logic to send email in HTML format and it was working fine. But now i have to add an attachment to the email. I am able to send plain text email with attachment but with HTML content, the text file is not getting attached with the email.

services that i am using are :

  1. pub.io.stringToStream

  2. pub.mime.createMimeData
    input(s)
    -----mime-header/content-type = text/html
    -----mime-header/x-priority = 1

  3. pub.mime.addBodyPart
    input(s)
    -----mimeData = [created in previous step above(2)]
    -----content = [created in first step above(1)]
    -----contentTyp = text/html

  4. pub.mime.getEnvelopStream
    input(s)
    -----mimeData = [created in previous step above(3)]

  5. pub.client.smtp
    input(s)
    -----to
    -----cc
    -----subject
    -----from
    -----mail host
    -----mimeStream = [created in previous step above(4)]
    -----attachments
    -----input(s)
    ---------contentType=text/html
    ---------fileName=newFile.txt
    ---------content=[string value]/[stringToStream for the input]/[stringToBytes for the input]
    ---------encoding=none
    ---------charset=none

Please suggest, Thanks in advance.

Hi,

I do not know if in the mean time you have managed to fix this, but please find below the solution that works for me.

(1)
pub.string:stringToBytes
INPUTS:
string: body of the mail
encoding: ISO-8859-1
OUTPUT: bytes

(2)
pub.io:bytesToStream
INPUT:
bytes from point 1
OUTPUT:
stream

(3)
pub.mime:createMimeData
INPUTS:
stream from point 2
subtype: multipart/mixed
OUTPUTS:
mimeData object
stream object

(4)
pub.mime:addBodyPart - to add the mail body
INPUTS:
mimeData and stream objects from point 3
contenttype: text/html
OUTPUTS:
mimeData object

(5)
prepare your attachment - read it from the disk or something else

(6)
pub.mime:addBodyPart - to add the mail attachment from point 5
INPUTS:
mimeData from point 4
content prepared at point 5
isEnvStream: false
mimeHeader: form-data; name=“fileID”; filename=%Filename% (actually the filename of the pdf i am sending)
contenttype: application/pdf
encoding: base64
multipart: no
OUTPUT:
mimeData

(7)
pub.mime:addMimeHeader
INPUTS:
mimeData from point 6
mimeHeader: init to empty
OUTPUTS:
mimeData

(8)
pub.mime:getEnvelopeStream
INPUTS:
mimeData from point 7
OUTPUT:
envStream

(9)
pub.client:smtp
INPUTS:
the envStream from point 8
all your other defined
body input param is not mapped
OUTPUT:
who cares :), just check your mail


Please let me know if this works for you.

Or for others that are faced with the same problem.

Some tweaking might be necessary depending of the content you want to add as attachment.

Sending HTML mail is rather easy. Sending plain text mail with attachnments is not that hard as well, but having both at the same time is kinda complicated.

Hope this helps,
Vlad Turian

1 Like

Thanks Vlad, yes I have managed to get it resolved.

Cheers!!
Abhishek