I have received help from many on the forum concerning this subject.
I've got a UX with a list of email recipients (it is pulled from a SQL query that filters based on certain criteria). When a list row is selected, a viewbox with an email message is populated. Wanting to have a bulk mail solution that sends individual, personalized emails to each member of the email recipient list with one button click.
I have been using an "it works" solution that successfully generates the viewbox, pulls the HTML from viewbox, and sends the email via SparkPost. It isn't ideal as I have to manually select the row in a list (I sent about 500 emails earlier this week, manually clicking through), then press a send button. I figured out a way to eliminate the button press, but in the ideal world I would open the UX which would generate the list of email recipients and then press a "go" button that loops through each recipient, generates the unique viewbox with the email text, sends the HTML back to the xbasic, and then sends the email to each one. I am sure a loop is possible, and many posts on the forum even state that the loop is the easy part. Well, I've been trying to figure this out for the better part of a year (when I had free time) and I'm still stuck.
Basically, in debug I can see that my loops is successfully iterating through the list of recipients, but something about the way I pull the innerHTML into xbasic is not updating the viewbox data for each iteration of the list - so the HTML for the email remains the same as the first recipient for all people on the list.
and the code that generates the HTML
Any guidance? I find the documentation for Viewboxes less than helpful and I'm sure they are amazing and very powerful, but I'm just not experienced enough yet to figure this out.
I've got a UX with a list of email recipients (it is pulled from a SQL query that filters based on certain criteria). When a list row is selected, a viewbox with an email message is populated. Wanting to have a bulk mail solution that sends individual, personalized emails to each member of the email recipient list with one button click.
I have been using an "it works" solution that successfully generates the viewbox, pulls the HTML from viewbox, and sends the email via SparkPost. It isn't ideal as I have to manually select the row in a list (I sent about 500 emails earlier this week, manually clicking through), then press a send button. I figured out a way to eliminate the button press, but in the ideal world I would open the UX which would generate the list of email recipients and then press a "go" button that loops through each recipient, generates the unique viewbox with the email text, sends the HTML back to the xbasic, and then sends the email to each one. I am sure a loop is possible, and many posts on the forum even state that the loop is the easy part. Well, I've been trying to figure this out for the better part of a year (when I had free time) and I'm still stuck.
Basically, in debug I can see that my loops is successfully iterating through the list of recipients, but something about the way I pull the innerHTML into xbasic is not updating the viewbox data for each iteration of the list - so the HTML for the email remains the same as the first recipient for all people on the list.
Code:
function sendmail as c (e as p) dim p as p p = json_parse(e._listData) for each donor in p e._set.id.value = donor.w_sponsor_id e._set.names.value = donor.w_sponsor_id dim js as c = "" dim email as c email = "" email = donor.email dim ix as n dim tmpl as p tmpl = e.tmpl ix = tmpl.page_fields.findi("vb","v.variablename") if ix > 0 then dim json as c json = tmpl.page_fields[ix].v.viewbox.definitionJSON dim p as p p = json_parse(json) dim css as c css = p.formview.css end if dim html as c = "" html = "<html><head><style>" + css + "</style></head><body>" + crlf() + e._html + "</body></html> dim MyOrganizationEmailAddress as c = "[email protected]" dim SparkpostKey as c = secret sparkpost key dim pm as p pm.send_to = email pm.from_name = "Some guy pm.from_email = MyOrganizationEmailAddress pm.subject = "Thank You" pm.message_html = html pm.attachments = "c:\A5Webroot\PC\Results.pdf" pm.message_text = "" 'this property is very important. if you don't set this property the email message will not use the stylesheet pm.options.inline_css = .t. dim pResult as p 'pResult = email_send_sparkpost(SparkpostKey,pm) sendmail = js next end function
Code:
var html = $('viewboxcontent').innerHTML; //var data = A5.ajax.buildURLParam('_html',html); var list = {dialog.object}.getListData('names'); var dataJSON = JSON.stringify(list); var _dataToSubmit = A5.ajax.buildURLParam('_listData',dataJSON)+"&"+A5.ajax.buildURLParam('_html',html); {dialog.object}.ajaxCallback('','','sendmail','',_dataToSubmit); setTimeout(function(){ alert('Here is what we sent:'+html);},2000);
Comment