Chapter 3 DynaScript Predefined Objects


mailPiece methods (outgoing)

The mailPiece object has these methods:

AddRecipient method

Syntax

mailPiece.AddRecipient( userName [, userMode] )

Description

Specifies the address or addresses where a mail piece is to be sent. The parameters are:

Return

Boolean.

Example

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>

See also

"attachment object".

"mailPiece object (incoming)".

"mailList object".

"recipient object".

AddReplyTo method

Syntax

mailPiece.AddReplyTo( userName )

Description

Adds an address to the list of addresses from which responses to this mail piece are directed.

Return

Boolean.

Example

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();
-->

See also

"attachment object".

"mailPiece object (incoming)".

"mailList object".

"recipient object".

AttachData method

Syntax

mailPiece.AttachData( data [,MIMEtype, description] )

Description

Attaches a piece of data (typically held in a DynaScript variable) to the mail piece.

Return

Boolean.

Example

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();
-->

See also

"mailPiece object (incoming)".

"mailList object".

"recipient object".

"AttachDocument method".

"AttachFile method".

AttachDocument method

Syntax

mailPiece.AttachDocument( documentName )

Description

Attaches a document in a PowerDynamo Web site to the mail piece.

Return

Boolean.

Example

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();
-->

See also

"attachment object".

"mailPiece object (incoming)".

"mailList object".

"recipient object".

"AttachData method".

"AttachFile method".

AttachFile method

Syntax

mailPiece.AttachFile( filePath )

Description

Attaches a file from the file system to the mail piece.

Return

Boolean.

Example

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();
-->

See also

"attachment object".

"mailPiece object (incoming)".

"mailList object".

"recipient object".

"AttachData method".

"AttachDocument method".

GetErrorCode method

Syntax

mailPiece.GetErrorCode( )

Description

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.

Return

Integer.

Example

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() );
}
-->

See also

"mailPiece object (incoming)".

"mailList object".

"GetErrorInfo method".

GetErrorInfo method

Syntax

mailPiece.GetErrorInfo( )

Description

Returns a string containing an error message. The message is either a reply either from the SMTP server or from PowerDynamo.

Return

String.

Example

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() );
}
-->

See also

"mailPiece object (incoming)".

"mailList object".

"GetErrorCode method".

Send method

Syntax

mailPiece.Send( userName )

Description

Sends a mail piece through SMTP. Use GetErrorInfo and GetErroCode to check for failures.

Return

Boolean.

Example

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();
-->

See also

"mailPiece object (incoming)".

"mailList object".

"GetErrorCode method".

"GetErrorInfo method".

 


Copyright © 1999 Sybase, Inc. All rights reserved.