Chapter 3 DynaScript Predefined Objects


mailPiece object (outgoing)

Object

Represents a mail piece that is to be sent via SMTP.

Syntax

To use a mailPiece property:

mailPiece.propertyName 

To use a mailPiece method:

mailPiece.MethodName( parameter ) 

Description

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.

Example

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

See also

"attachment object"

"mailPiece object (incoming)"

"mailList object"

"recipient object"

body property

Syntax

mailPiece.body

Attributes

This property is read/write.

Description

The body text of the mail piece.

Note  

Binary data
Binary data must be sent as an attachment.

Example

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

See also

"attachment object"

"mailPiece object (incoming)"

"mailList object"

"recipient object"

from property

Syntax

mailPiece.from

Attributes

This property is read/write.

Description

The address from where the mail piece is being sent. This address must be a valid Internet mail user name in canonical form.

Example

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>

See also

"attachment object"

"mailPiece object (incoming)"

"mailList object"

"recipient object"

sender property

Syntax

mailPiece.sender

Attributes

This property is read/write.

Description

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.

Example

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

See also

"attachment object"

"mailPiece object (incoming)"

"mailList object"

"recipient object"

smtpHost property

Syntax

mailPiece.smtpHost

Attributes

This property is read/write.

Description

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.

Example

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

See also

"attachment object".

"mailPiece object (incoming)".

"mailList object".

"recipient object".

body property

Syntax

mailPiece.body

Attributes

This property is read/write.

Description

The body text of the mail piece.

Note  

Binary data
Binary data must be sent as an attachment.

Example

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

See also

"attachment object"

"mailPiece object (incoming)"

"mailList object"

"recipient object"

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 © 2001 Sybase, Inc. All rights reserved.