Chapter 3 DynaScript Predefined Objects
The mailPiece
object
has these methods:
mailPiece.AddRecipient( userName [, userMode] )
Specifies the address or addresses where a mail piece is to be sent. The parameters are:
to
recipient
is the main target of the mail piece.
cc
recipient
is being carbon-copied.
bcc
recipient
is being blind carbon-copied.
Boolean.
The following example sends a piece of mail to a specific address depending on the input given by the user. The user must also enter their own e-mail address so the recipient will know who to respond to.
This script creates a form that requests information from the user:
<HTML>
<BODY>
<H1>Problem tracking</H1>
<p>This Web page is used to filter software problems to the appropriate help personel.
<p>Select the product that you require help for:
<FORM METHOD=POST ACTION='mailsend.ssc'>
<OL>
<LI><INPUT TYPE='radio' Name="product" Value="Product A">Product A
<LI><INPUT TYPE='radio' Name="product" Value="Product B">Product B
<LI><INPUT TYPE='radio' Name="product" Value="Product C">Product C
<LI><INPUT TYPE='radio' Name="product" Value="Product Other">Product Other
</OL>
<P>Enter your mail address:
<INPUT Type="TEXT" Name="from" SIZE=40></P>
<P>Describe your problem:
<INPUT Type="TEXT" Name="body" SIZE="50" ></P>
<INPUT TYPE="SUBMIT">
</FORM>
</BODY>
</HTML>
From a browser, the form looks something like this:
this is the script (mailsend.ssc) to process information entered on the form:
<HTML>
<BODY>
<!--SCRIPT mailsend.ssc
product = document.value.product
from = document.value.from
body = document.value.body
mp = new MailPiece();
switch( product ) {
case "Product A":
mp.AddRecipient("prodA@sybase.com");
break;
case "Product B":
mp.AddRecipient("prodB@sybase.com");
break;
case "Product C":
mp.AddRecipient("prodC@sybase.com");
break;
case "Product Other":
mp.AddRecipient("other@sybase.com");
break;
}
mp.subject = "Mail Piece Example";
mp.from = from;
mp.body = body;
if( !mp.Send() ) {
document.writeln( mp.GetErrorCode() );
document.writeln( mp.GetErrorInfo() );
}
-->
<P>Select the back button if you wish to send another e-mail</P>
</BODY>
</HTML>
"mailPiece object (incoming)".
mailPiece.AddReplyTo( userName )
Adds an address to the list of addresses from which responses to this mail piece are directed.
Boolean.
This mail piece, when replied to, will be sent to elmo and elmojr:
<!--SCRIPT
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddReplyTo = "elmojr@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "Request for comment";
mp.body = "Your input is needed immediately";
mp.Send();
-->
"mailPiece object (incoming)".
mailPiece.AttachData( data [,MIMEtype, description] )
Attaches a piece of data (typically held in a DynaScript variable) to the mail piece.
Boolean.
This example attaches a piece of data to the mail piece after retrieving it from the database:
<!--SCRIPT
myQuery = connection.CreateQuery( "select data from ImageTable where name = 'muppets'" );
myQuery.MoveNext();
imageData = myQuery.GetValue(1);
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "Request for comment";
mp.body = "Your input is needed immediately. Please review the attached graphic";
mp.AttachData( imageData, "image/jpg", "gorgeous.jpg" );
mp.Send();
-->
"mailPiece object (incoming)".
mailPiece.AttachDocument( documentName )
Attaches a document in a PowerDynamo Web site to the mail piece.
Boolean.
This example attaches a document called muppets.gif to the mail piece object:
<!--SCRIPT
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "Request for comment";
mp.body = "Your input is needed immediately. Please review the attached document";
mp.AttachDocument("~/mail/muppets.gif");
mp.Send();
-->
"mailPiece object (incoming)".
mailPiece.AttachFile( filePath )
Attaches a file from the file system to the mail piece.
Boolean.
This example attaches a system file called autoexec.bat to the mail piece object:
<!--SCRIPT
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "File update";
mp.body = "Your file should look something like the attached.";
mp.AttachFile("c:\\autoexec.bat");
mp.Send();
-->
"mailPiece object (incoming)".
mailPiece.GetErrorCode( )
Returns a code representing the most recent error that occurred. The error is either a three-digit SMTP reply code or a three-digit code in the 900 range generated by PowerDynamo.
Integer.
This example sends a piece of mail and then checks for errors:
<!--SCRIPT
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "Request for comment";
mp.body = "Your input is needed immediately. Please review the attached Dynamo document";
mp.AttachDocument("~/mail/muppets.gif");
mp.Send();
if( !mp.Send() ) {
document.writeln( mp.GetErrorCode() );
document.writeln( mp.GetErrorInfo() );
}
-->
"mailPiece object (incoming)".
mailPiece.GetErrorInfo( )
Returns a string containing an error message. The message is either a reply either from the SMTP server or from PowerDynamo.
String.
This example sends a mail piece and then checks for errors:
<!--SCRIPT
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "Request for comment";
mp.body = "Your input is needed immediately. Please review the attached Dynamo document";
mp.AttachDocument("~/mail/muppets.gif");
mp.Send();
if( !mp.Send() ) {
document.writeln( mp.GetErrorCode() );
document.writeln( mp.GetErrorInfo() );
}
-->
"mailPiece object (incoming)".
mailPiece.Send( userName )
Sends a mail piece through SMTP. Use GetErrorInfo
and GetErroCode
to check
for failures.
Boolean.
This example creates and sends a mail piece:
<!--SCRIPT
mp = new MailPiece();
mp.from = "elmo@sybase.com";
mp.AddRecipient( "sam@sybase.com" );
mp.subject = "Request for comment";
mp.body = "Your input is needed immediately";
mp.Send();
-->
"mailPiece object (incoming)".
Copyright © 1999 Sybase, Inc. All rights reserved. |