1. mathews rutto
  2. PowerBuilder
  3. Tuesday, 3 December 2024 20:54 PM UTC

Hi, this code word perfectly but it's only sending one attachment and i need to send two attachments as indicated below.

Please help.

ls_item = 'abc.pdf'
ls_file = "D:\" + ls_item

ls_item2 = '123.xls'
ls_file2 = "D:\"+ ls_item2

//Read the file into a blob
ll_FileNum = FileOpen(ls_file,StreamMode!)
if ll_FileNum > 0 then
     FileReadEx(ll_FileNum, blb_file)
     FileClose(ll_FileNum)
else
     MessageBox('File Error',  'Error Opening Filename ' + ls_file)
     return
end if

// Read the file into a blob
ll_FileNum2 = FileOpen(ls_file2, StreamMode!)
if ll_FileNum2 > 0 then
     FileReadEx(ll_FileNum2, blb_file1)
     FileClose(ll_FileNum2)
else
     MessageBox('File Error',  'Error Opening Filename ' + ls_file2)
     return
end if        

// Create component blobs
blb_multipart = blob('--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_multipart += blob('Content-Disposition: form-data; name="to"' + '~r~n~r~n' + ls_email + '~r~n', EncodingUTF8!)
                
blb_multipart += blob('--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_multipart += blob('Content-Disposition: form-data; name="subject"' + '~r~n~r~n' + ls_subject + '~r~n', EncodingUTF8!)

blb_multipart += blob('--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_multipart += blob('Content-Disposition: form-data; name="text"' + '~r~n~r~n' + ls_text + '~r~n', EncodingUTF8!)

blb_multipart += blob('--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_multipart += blob('Content-Disposition: form-data; name="cc"' + '~r~n~r~n' + ls_null + '~r~n', EncodingUTF8!)    

blb_multipart += blob('--' + ls_boundary + '~r~n', EncodingUTF8!)
blb_multipart += blob('Content-Disposition: form-data; name="attachment1"; filename="'+ ls_item +'"~r~nContent-Type: application/*~r~n~r~n', EncodingUTF8!) + blb_file
blb_multipart += blob(ls_file, EncodingUTF8!)

blb_multipart += blob('--' + ls_boundary + '~r~n', EncodingUTF8!)
blb_multipart += blob('Content-Disposition: form-data; name="attachment2"; filename="'+ ls_item2 +'"~r~nContent-Type: application/*~r~n~r~n', EncodingUTF8!) + blb_file1
blb_multipart += blob(ls_file2, EncodingUTF8!)

blb_multipart += blob('~r~n--' + ls_Boundary + '--~r~n', EncodingUTF8!)

// Send the request
lnv_HttpClient = create HTTPClient
lnv_httpClient.SetRequestHeader("CM-API-KEY", "7eb774f033f0fc5f2c73284d9767058debc98f43dd1110cea80c294313037c99")    
lnv_httpClient.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + ls_BOUNDARY)    
li_rc = lnv_httpClient.SendRequest('POST', ls_endpoint, blb_multipart)

// obtain the response data
if li_rc = 1 then
    
     li_ResponseStatusCode = lnv_HttpClient.GetResponseStatusCode()
     ls_ResponseStatusMessage = lnv_HttpClient.GetResponseStatusText()
     lnv_HttpClient.GetResponseBody(ls_ResponseBody, EncodingUTF8!)
                    
     if li_ResponseStatusCode = 200 then
     //Okay
     end if
end if

René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 4 December 2024 05:48 AM UTC
  2. PowerBuilder
  3. # 1

Hi,

I don't understand what this lines are for. Maybe you don't need them:

blb_multipart += blob(ls_file, EncodingUTF8!)
...
blb_multipart += blob(ls_file2, EncodingUTF8!)
...

I don't know anything about the endpoint you are using. Maybe you have to send the files base64 encoded?

Comment
  1. mathews rutto
  2. Wednesday, 4 December 2024 09:39 AM UTC
After removing them still not sending two attachments.

  1. Helpful
  1. John Fauss
  2. Wednesday, 4 December 2024 16:21 PM UTC
I think you should review any RestAPI documentation you have from the mail service/endpoint provider and perhaps contact them for guidance. Without knowing anything about what service you are using, I am doubtful that we will be able to help you.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 4 December 2024 18:42 PM UTC
It would be helpful if you told us what service you are using.
  1. Helpful
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Wednesday, 4 December 2024 17:33 PM UTC
  2. PowerBuilder
  3. # 2

Hi Mathews,

Your content-type identifiers for each file don't look right as I haven't seen application/* used before, but maybe it should still be able to work (and I guess it works with one of the files). Instead of sending a PDF and an XLS file, try sending two PDFs and see if they both make it to the intended destination using application/*.  You may wish to try sending each file separately first just to make sure it can be successfully sent that way, then work on sending them together.  By the way, which attachment actually gets sent, the PDF or the XLS (and can you successfully open the file that was sent)?  

If that still fails...and I'm guessing it will...then try application/pdf and application/vnd.ms-excel respectively for each file and see if that makes a difference.

HTH...regards,

Mark

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.