I am using this code to send out multiple reports to multiple recipients. The problem is that it's only sending the first report to the multiple recipients.
EXAMPLE:
User1@xx.com - Should get Report #1
User2@xx.com - Should get Report #1
User1@xxcom - Should get Report #2
User2@xx.com - Should get Report #2
What's happening is that User1@xx.com and User2@xx.com will get Report #1 twice. Report #2 is never picked up and mailed out to recipients.
string ls_email, ls_link,ls_freq, ls_rptnbr,ls_message,ls_address, ls_msg, ls_subject, ls_file, ls_text, path, ls_attach,ls_location,ls_reportonly, ls_analyst
string ls_recipient, ls_ccrecipient, ls_bccrecipient, ls_attachment, ls_sender, ls_rec, ls_run, ls_analystabr, ls_sdate,ls_fileattach[]
string ls_filename[],ls_mimetype,ls_boundary,ls_url,ls_json, is_server, is_userid, is_passwd
date ldt_randate, ldt_today
boolean lb_run ;lb_run = FALSE
boolean lb_count ;lb_count = FALSE
Boolean lb_html, lb_Return
blob blb_file[],blb_boundary,blb_terminus,blb_multipart
blob blb_recipient,blb_subject,blb_message
integer ll_filenum,li_count,li_nbr, li_rptnbr, ls_ret, li_seqno
UInt lui_port
HttpClient inv_httpClient
inv_httpClient = CREATE HttpClient
inv_httpClient.SecureProtocol=5 /*TLS 1.2*/
SetPointer(HourGlass!)
lb_html = False
lui_port =25
is_userid = <USER EMAIL>
is_passwd = <PASSWORD>
select sysdate
into :ldt_today
from dual;
ls_sdate = string(date(ldt_today))
DECLARE GetEAddress CURSOR FOR
SELECT tolist(e_address), rpt_nbr, frequency, file_location, Report_Only, analyst, seq_no
FROM <TABLE>
group by rpt_nbr, frequency, file_location, Report_Only, analyst, seq_no;
OPEN GetEAddress;
if sqlca.SQLCODE <> 0 then
messagebox("No","No records")
CLOSE GetEAddress;
return
else
FETCH GetEAddress
INTO :ls_email, :li_rptnbr, :ls_freq, :ls_link, :ls_reportonly, :ls_analyst, :li_seqno;
end if
IF sqlca.SQLCODE = 0 then
DO WHILE ( sqlca.SQLCODE = 0 )
if sqlca.SQLNRows <> 0 then
ls_text = string(li_rptnbr) +" - " + ls_analyst
select subject, message, file_location, run
into :ls_subject, :ls_msg, :ls_file, :ls_run
from <TABLE>
where <>
choose case li_rptnbr
case IS > 1
if ls_run = 'Y' then
lb_run=TRUE
SELECT tolist(e_address)
INTO :ls_email
FROM <TABLE>
where <>
order by e_address asc;
ls_attach = mid(ls_file, lastpos(ls_file,'\')+1,120)
path = left(ls_file, lastpos(ls_file,'\') )
blb_recipient = blob('Content-Disposition: form-data; name="Recipient"' + '~r~n~r~n' + ls_email, EncodingUTF8!)
blb_subject = blob('Content-Disposition: form-data; name="Subject"' + '~r~n~r~n' + ls_subject, EncodingUTF8!)
blb_message = blob('Content-Disposition: form-data; name="Message"' + '~r~n~r~n' + ls_msg, EncodingUTF8!)
if isnull(ls_msg) then
ls_msg = ""
ls_message = ls_msg
end if
ls_attachment = path + ls_attach
/* Get attachments and read into a blob */
li_count = 1
For li_nbr = 1 To li_count
ls_fileattach[li_nbr] = ls_attachment
ll_FileNum = FileOpen(ls_fileattach[li_nbr], StreamMode!)
FileReadEx(ll_FileNum, blb_file[li_nbr])
FileClose(ll_FileNum)
ls_FileName[li_nbr] = ls_fileattach[li_nbr]
Next
ls_MimeType = 'application/pdf'
/* Create a boundary marker for the multipart blob */
ls_BOUNDARY = "$$$Boundary$$$"
/* Create component blobs */
blb_boundary = blob('~r~n--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_terminus = blob('~r~n--' + ls_Boundary + '--~r~n', EncodingUTF8!)
For li_nbr = 1 To li_count
blb_file[li_nbr] = blob( 'Content-Disposition: form-data; name="file"; filename="' + ls_FileName[li_nbr] + '"' + '~r~n' + &
"Content-Type: " + ls_MimeType + "~r~n~r~n", EncodingUTF8!) + &
blb_file[li_nbr]
Next
/* Concatenate blobs into a single multipart blob */
For li_nbr = 1 To li_count
blb_multipart = blb_multipart + blb_boundary + &
blb_file[li_nbr]
Next
blb_multipart = blb_multipart + blb_boundary + &
blb_recipient + &
blb_boundary + &
blb_subject + &
blb_boundary + &
blb_message + &
blb_terminus
/* set email properties */
ls_location = "TEXT"
if li_rptnbr = 999 then
blb_subject = blob('Content-Disposition: form-data; name="Subject"' + '~r~n~r~n' + 'Updated Reports', EncodingUTF8!)
blb_message = blob('Content-Disposition: form-data; name="Message"' + '~r~n~r~n' + ls_location, EncodingUTF8!)
end if
if Not IsNull(ls_subject) and li_rptnbr <> 300 then
integer li_rtn
/* HTTPClient */
li_rtn = inv_httpClient.clearrequestheaders()
li_rtn = inv_httpClient.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + ls_BOUNDARY)
if isnull(li_rtn) or li_rtn <> 1 then messagebox('SetRequestHeader Failed',string(li_rtn))
ls_url = 'https://mailapi.dob.texas.gov/api/mail/sendmailattachment'
li_rtn = inv_httpClient.SendRequest('POST', ls_url, blb_multipart)
li_rtn = inv_httpClient.GetResponseBody(ls_json)
end if
end if
end choose
end if
FETCH NEXT GetEAddress
INTO :ls_email, :li_rptnbr, :ls_freq, :ls_link, :ls_reportonly, :ls_analyst, :li_seqno;
Loop;
END IF
CLOSE GetEAddress;
this is why I think it has something to do with the way you concatenate the attachments. As I've said already, I don't know anything about this way of sending email. We either use smtp, not using an http client or by using ole.
Sorry, I can't be of more help on this one.
regards.