Chapter 3 DynaScript Predefined Objects
Represents a mail piece that is to be sent via SMTP.
To use a mailPiece property:
mailPiece.propertyName
To use a mailPiece method:
mailPiece.MethodName( parameter )
Use the mailPiece constructor to create an outgoing mail piece object that represents a piece of outgoing mail. The syntax is:
mailPiece = new MailPiece( );
You can also create outgoing mail pieces by calling the Forward, Redirect or Reply method on an incoming mail piece object.
This example creates and sends a simple mail piece with an attachment:
mp = new MailPiece(); mp.subject = "This is my subject text"; mp.from = "elmo@sybase.com"; mp.body = "This is my mail piece body."; mp.smtpHost = "mail.sybase.com"; mp.AddRecipient( "theGrouch@sybase.com"); mp.AttachDocument( "attachment.gif" ); if( !mp.Send() ) { document.writeln( mp.GetErrorCode() ); document.writeln( mp.GetErrorInfo() ); }
mailPiece.body
This property is read/write.
The body text of the mail piece.
Binary data
Binary data must be sent as an attachment.
This example creates an outgoing mail piece. It is assumed that you have set the smtpHost from within Sybase Central:
<!--SQL mp = new MailPiece(); mp.subject = "Example of the body property"; mp.from = "elmo@sybase.com"; mp.body = "This is the body of the outgoing mail piece."; mp.AddRecipient( "theGrouch@sybase.com" ); if( !mp.Send() ) { document.writeln( mp.GetErrorCode() ); document.writeln( mp.GetErrorInfo() ); } -->
mailPiece.from
This property is read/write.
The address from where the mail piece is being sent. This address must be a valid Internet mail user name in canonical form.
This example sends a piece of e-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 knows to whom to respond to.
Following is the 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 would look something like this:
Following is the script (mailsend.ssc) that is called to process the 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 buttom if you wish to send another e-mail</P> </BODY> </HTML>
mailPiece.sender
This property is read/write.
You can use this property if a mail piece is
sent from a destination other than that of the person who the message
is from. For example, if an assistant wanted to send a message as
requested by their supervisor, mailPiece.sender
would
be the address of the assistant while mailPiece.from
would
be the address of the supervisor.
This example sets the sender property on the mp mailpiece object:
<!--SCRIPT mp = new MailPiece(); mp.from = "elmo@sybase.com"; mp.sender = "elmojr@sybase.com"; mp.AddRecipient( "oscar@sybase.com" ); mp.subject = "Request for comment"; mp.body = "Your input is needed immediately"; mp.Send(); -->
mailPiece.smtpHost
This property is read/write.
Specifies the name of the host to be used as a gateway for sending the mail piece. If this value is empty, the value of smtpHost in the PowerDynamo Configuration folder is used as the gateway. If the smtpHost has not been specified in Sybase Central or the document, the mail piece will not be sent.
For information on setting the smtpHost in Sybase Central see "Changing Dynamo configuration settings" in the PowerDynamo User's Guide.
This example sets the smtpHost as mailsrv.sybase.com:
<!--SCRIPT mp = new MailPiece(); mp.from = "elmo@sybase.com"; mp.sender = "elmojr@sybase.com"; mp.AddRecipient( "oscar@sybase.com" ); mp.smtpHost="mailsrv.sybase.com"; mp.subject = "Request for comment"; mp.body = "Your input is needed immediately"; mp.Send(); -->
"mailPiece object (incoming)".
mailPiece.body
This property is read/write.
The body text of the mail piece.
Binary data
Binary data must be sent as an attachment.
This example creates a simple outgoing 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.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.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.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.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.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.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.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(); -->
Copyright © 2001 Sybase, Inc. All rights reserved. |
![]() |