1. LeVerne Johnson
  2. PowerBuilder
  3. Monday, 13 March 2023 03:45 PM UTC

 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;

 

 


Responses (2)
  1. Likes
  2. Latest
  3. Oldest
Loading...

Find Questions by Tag

.EXE .NET 6.0 .NET Assembly .NET Core 3.1 .NET Core Framework .NET DataStore .NET Std Framework 32-bit 64-bit ADO.NET AEM AI Algorithm Amazon AWS Android Apache API APK App Store App Store (Apple) Appeon Workspace Appeon Xcelerator Plug-in Architecture Array ASE Asynchronous Methods Authentication AutoBuild AutoCompiler Automated Testing Automation AutoScript Azure Barcode Base64 Batch BigData BLOB Branch & Merge Browser Bug Build Button C# C# Class Importer C# Editor C# Model generator Calendar Camera Certificate Chrome Citrix Class Client Client/Server Cloud Cluster Collection COM Command Line Compiler Compression Computed Field Configuration Controls Cookies Cordova Crash Cross-Platform Crosstab CSharpAssembly CSharpObject CSS CSV Cursor Data Database Database Driver Database Painter Database Profile Database Provider DataObject DataSource DataStore DataStore (C#) DataStore (PS) DataType DataWindow DATE DATETIME DB2 Debug Debugger Debugging Deployment Design DLL DO-WHILE Dockable Docker Documentation DOUBLE Download DragDrop Edge Edit Style Editor Elevate Conference Email Embedded SQL Emulator Encoding Encryption Enhancement Request Entity Entity Framework ERP Error Event Event Handler Event Handling Excel Exception Export Expression External Functions F# Field File File Access Filter Firefox Firewall Font FOR-NEXT Foreground Format Function Garbage Collection GeoLocation Git Graph HANA Hash Header HTML/5 HTTP/S HTTPClient Icon IDE Identity IIS IMAPI Import InfoMaker Inheritance Installation Integer IntelliSense Interface Internet Internet Explorer iOS IPA iPad iPhone IWA J# Java JavaScript JBoss JDBC JOIN JSON JSONGenerator JSONParser Kestrel Label Lambda Large File LDAP Library License LINQ Linux OS Load Balancing Localization Localized PBVM Log In Log Out Logging LONG LONGLONG macOS MAPI Maps MDI Memory Memory Leak Menu Merge MessageBox Messagging Method Migration MIME TYPE Mobile Model ModelStore ModelStore (C#) MSOLEDBSQL Multi Threading MVC MySQL n-Tier Namespace NativePDF NVO OAuth ODATA ODBC Office Offline OLE OLEDB Online Open Source OpenAPI OpenSSL Oracle OrcaScript Other Outlook Output Package Parameter Patch PayPal PB Classic PB Native PB.NET PBC PBD PBDOM PBG PBJVM PBL PBNI PBORCA PBVM PBX PDF Performance Permission PFC Picture Pipeline Play Store (Google) Plugin Popup Port POST PostgreSQL PowerBuilder PowerBuilder (Appeon) PowerBuilder (SAP) PowerBuilder Compiler PowerBuilder Runtime PowerClient PowerScript (PS) PowerScript IDE PowerScript Migrator PowerServer PowerServer Mobile PowerServer Toolkit PowerServer Web PowerServerLabel Print Properties Proxy Publish PULL PUSH Query Regression Release Renew Resize Response REST Retrieve RibbonBar RibbonBar Builder Rich Text Roadmap RPC Runtime Packager SaaS Scaffolding Script SDI SDK Security Server Service Session Single Sign-on Size SMTP SMTPClient SnapDevelop SOAP Sort Source Code Speech Recognition SQL SQL Anywhere SQL Server SqlBuilder SqlExecutor SQLite SqlModelMapper Storage Stored Procedure Subscription SVN Swagger Syntax TabbedBar TabbedView Tablet TabPage Target TE Control Testing Text TFS Theme TIME Timer TLS/SSL Tomcat TortoiseGit TortoiseSVN Transaction Transparency Trial Trigger TRY-CATCH TX Control Type UI ULONG UltraLite Uninstall Unit Test Unit Testing UNIX OS Update Upgrade Upload URL User Center User Object UWP Validation VARCHAR Variable Versioning Visual Studio Visual Studio Code VM Voice Warning WCF Web API Web Extensions Web Service WebBrowser WebForms WebLogic WebSphere WildFly WinAPI Window Windows OS WinForms Wizard Workgroup Workspace WPF XCODE XHTML XML Zoom

Helpful?

If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.