Caravan Business Server>Help>Objects>SMTP (Mail) Object |
Syntax
|
<caravan>mail objectname</caravan>
|
Text
|
A SMTP (Mail) object is created with the property "from" set as the login userid of the User. SMTP (Mail) object can only be created by a logged in user. An object of type mail represents a single mail message received or to be sent. The mail object can be instantiated. It can also be created automatically on receipt of a mail. This object type is identical to VAR and can be used as such in all other ways. Notes 1. To send mail, a default SMTP Gateway has to specified in the Caravan.cnf file in the etc path: smtpgateway mail.domain.com 2. TCP/IP port 25 is used by Caravan for mail transactions. A listener is installed on this port automatically on startup. Caravan will accept incoming connections only if "mailaction" and "mailuser" scripts have been implemented. 3. Any output from (mailuser,mailaction,maildeliverystatus) scripts are sent to the console unless redirected by explicit "output" statement. 4. Currently all scripts are placed in the templates directory with .html extension.
|
Sample
|
1. Mailaction Mailaction is a script for handling mail that is received. An object of type mail and name "mail" is the input. The script can examine the properties and take requisite action or redirect to another gateway by setting the smtpgateway property. It is the responsibility of this script to handle the incoming mail. The object is deleted if it is not redirected. Do not delete this object by explicit delete statement. Example
<caravan> user x; "mail for ";mail(to);" from ";mail(from);"\n"; // output to console the recipients' and senders' names x(userid)=mail(to) ifx(uid) table t=mail.data t(text)=mail(text) t(from)=mail(from) t(subject)=mail(subject) t(attachment)=mail(attachment) // etc. etc else mail("smtpgateway")="nextcenter" endif </caravan>
2. Mailuser Mailuser is a script for verifying whether incoming mail is to be accepted for a particular user. An object named "recipient" with the property "name" is the input. Set the "accept"property to an attribute, say "ok", if the mail addressed by "name" can be delivered by "mailaction". Do not set this property if the said user is not available! Example <caravan> user x x(userid)=recipient(name) if x(uid) recipient(accept)="ok"; // can be anything endif </caravan> 3. Mail(deliverystatus) Mail(deliverystatus) is a script for handling the status of the mail delivery (success/failure) and follow up actions. When an object of the type mail is created it is automatically relayed to the smtpgateway specified in its properties or through the smtpgateway specified in the configuration. When the mail is sent, maildeliverystatus.html is activated and the objects' property "maildeliverystatus" indicates the status as success or failure. For each "to" there is a corresponding "accept" property set to "ok" or some other value (indicating failure), which helps in deciding what action needs to be taken. Example For receiving mail <caravan> if mail(deliverystatus)="ok"; // the object name is "mail" regardless of the name of the original object // the object is intact except for the properties added "deliverystatus" and "accept" loop x (mail(to(@0))) ;// for all users check delivery status if mail(accept(x(count)))="ok" "mail delivered to: ";mail(to(x(count)));"\r\n"; // output this to console else "mail to user:";mail(to(x(count)));"could not be sent\r\n"; endif repeat x 100 else "mail"; mail(subject); "form ";mail(from);" was not delivered to any of the recipients\r\n" endif </caravan> Example For sending mail <caravan> mail x file image="f:\images\picture.gif"x(to)="user@domain.com";// mandatory x(subject)="File with images" x(text)=" I am sending you a mail\r\nwith two attached images." x(attachment)=image(file) delete image file image="f:\images\picture1.gif" x(attachment=image(file);// number of attachments and their size may be limited // by the receiver smtp or intervening gateways x(smtpgateway)="localhost"; // optional; default will be used if notset </caravan>
|
Properties
|
To
subject
Text
attachment
smtpgateway
|
Back
|