Contents

 
Home
ASPRunner Professional 7.1 manual
Prev Page Next Page
 
 

Send an email to selected users

 

Sometimes you need to send an email to selected users. Let's say one of the fields on a page EmailField contains user email. The key field on the page is KeyColumn, table name - TableName.

Let's consider two situations:

yellowbulbNote: Change the values listed in red to match your specific needs.

1. Proceed to the Visual Editor page.

2. Create the custom button (e.g. "Email selected") and add the following code

to the Server tab:

response.Flush

dim arr,i

currentTable = "TableName"

 

if keys.Count>0 then

  email_list=""

  set rmail=CreateDictionary()

  for i=0 to keys.Count-1

     arr=split(keys.Item(i)("KeyColumn"),"&")

    if asp_count(arr)>=0 then

        set arr2=CreateDictionary()

        arr2("KeyColumn")=asp_urldecode(arr(0))

        where = KeyWhere(arr2,"")

        set data = dal.Table(currentTable).Query(where,"")

        if data("EmailField")<>"" then

           email_list=email_list & data("EmailField")  & ","

        end if

        data.close

        set data=nothing

    end if

  next

  if email_list<>"" then

     email_list = left(email_list,len(email_list)-1)

  end if

  ' send the email

  rmail("to")=email_list

  rmail("subject")="Sample subject"

  rmail("body")="Your email message here"

  set arr = runner_mail(rmail)

  result("txt") = "Emails were sent."

 

  ' if error happened print a message on the web page

  if arr("mailed") then

     errmsg = "Error happened: <br>"

     errmsg = errmsg & "File: " & arr("source") & "<br>"

     errmsg = errmsg & "Line: " & arr("number") & "<br>"

     errmsg = errmsg & "Description: " & arr("description") & "<br>"

     result("txt") = errmsg

  end if

end if

and to the Client After tab:

var message = result["txt"];

ctrl.setMessage(message);

The Client Before tab should be blank (delete sample code there if any).

yellowbulbNote: Change the values listed in red to match your specific needs.

1. You should create a new table (e.g. email_table) with "From", "Subject" and "Body" fields (components of the email) and adjust the Add page to this table with these fields. You can use one of the existing tables instead of creating new one.

2. To create new button "email selected", proceed to the Visual Editor page. Switch to the HTML mode and add the following code:

echo'<SPAN class=runner-btnframe>

<SPAN class=runner-btnleft></SPAN>

<SPAN class=runner-btnright></SPAN>

<A class=runner-button href="#" id="email_selected1">Email selected</A>

</SPAN>';

3. Add the following code to the List page: JavaScript onload event event to create an "onclick" event:

var submitUrl = "email_table_add.asp";

if (typeof id == "undefined"){

 id = this.id;

}

 

pageObj = this;

$("#email_selected"+this.id).unbind("click").bind("click", function(e){

 var selBoxes = pageObj.getSelBoxes(pageid);

 if(selBoxes.length == 0 || !confirm('Do you really want to email these records?')){

   return false;

 }

 

 var form = new Runner.form.BasicForm({

    standardSubmit: true,

    submitUrl: submitUrl,

    method: 'POST',

    id: pageObj.id,

    baseParams: {"a": 'email'},

    addElems: pageObj.cloneFormElements(selBoxes)

});

 

 return openwin(form);

 form.destructor();

});

 

//define preWin function

var prevWin = null;

function openwin(oForm)

{

 if (prevWin && !prevWin.closed)

    prevWin.close();

 prevWin = window.open('', 'prevWin', 'left=200,top=200,width=750,height=620,status=0');

 oForm.target = 'prevWin';

 oForm.action = 'email_table_add.php';

 oForm.submit();

 if (prevWin && !prevWin.closed)

    prevWin.focus();

 return true;

}

4. The email is sent in the Add page: Before process event for the new table (email_table), so add the following code to this event:

if IsEqual(GetRequestValue(RequestForm(),"a"),"added") then

  set rstmp = Server.CreateObject("ADODB.Recordset")

  rstmp.open session("sql"), dbConnection

  while not rstmp.eof

    dim tmpDict

    set tmpDict = CreateObject("Scripting.Dictionary")

     tmpDict("to")=rstmp("EmailField")

     tmpDict("subject")=postvalue("value_Subject_1")

     tmpDict("htmlbody")=postvalue("value_Body_1")

     tmpDict("from")=postvalue("value_From_1")

     Response.Write "Sending email to " & rstmp("EmailField") & " ...<br>" :

     Response.Flush

    set ret=runner_mail(tmpDict)

    if not ret("mailed") then

        response.write ret("message")

    end if

     rstmp.MoveNext

  wend

 

  rstmp.Close : set rstmp=nothing

  session("sql") = ""

  Response.Write "<p><a href='javascript:window.close();'>Close window</a></p>"

  Response.End

else

  sql = "select EmailField from TableName where FieldName in ("

  for i=1 to request.form("selection[]").count

     sql = sql & request.form("selection[]")(i) & ","

  next

  sql = left(sql, len(sql)-1) & ")"

  session("sql")=sql

end if

Converted from CHM to HTML with chm2web Standard 2.85 (unicode)