Email class
The SMTP Helper for Janus SOAP and Janus Sockets is a high level, object oriented interface to client sockets that lets you write a User Language SMTP (Simple Mail Transfer Protocol) request without knowledge of socket level programming or the format of SMTP requests and responses.
The SMTP Helper methods let a User Language program act as an SMTP client. SMTP clients send mail requests to an SMTP server, not directly to other SMTP clients. The SMTP Helper methods only support communication with SMTP servers.
An SMTP server will “store and forward” mail it receives. This means that all messages are first received in entirety on the SMTP server, then the server attempts to deliver it to the recipients. Mail delivery can be delayed by a server that is down or too busy to accept connections. “Store and forward” gives the SMTP server the ability to retry delivery without making the SMTP client wait for completion.
A server might try to deliver a message for as long as a week or more. This, of course, makes it impractical for a client to wait for delivery confirmation, so the SMTP protocol does not provide such information. A “success” response from an SMTP server indicates only that the server has accepted the request and will attempt to deliver the mail to the recipients.
Most SMTP servers will at least confirm that any domain names in the recipient list are valid, but they cannot confirm that an actual recipient name is valid.
You must define a Janus [[JANUS CLSOCK|CLSOCK port to use the SMTP Helper. If you supply the IP address of the server and the port number in the port definition, SMTP applications need only know the Janus port name to communicate with the server. The following example defines a client socket port for use by SMTP applications. For more detailed information about defining Janus client socket ports, see JANUS DEFINE and JANUS CLSOCK.
JANUS DEFINE MYSMTP * CLSOCK 5 REMOTE 198.242.244.100 25
Note: To use the SMTP Helper objects, you must have licensed Janus Sockets and Janus SOAP. The Sirius object-oriented alternative to $functions is designed for Janus SOAP applications only, and information about using Sirius objects is provided in "Janus SOAP User Language Interface" and "Getting started with object-oriented programming for User Language programmers". For details about the object syntax in this chapter, see "Notation conventions for methods".
Feature Summary
The following capabilities are provided by the SMTP Helper:
- Creating general purpose e-mail for SMTP
- Sending general purpose e-mail via SMTP
- Setting e-mail content using Longstrings
- Sending MIME content (attachments and alternative content)
- Sending to multiple recipients
- Access to status (error or confirmation messages)
Email class
The SMTP Helper consists of a single object class:
Email
is the object with which you generate SMTP messages
(e-mail) to send to an SMTP server.
To construct a request, you use Email methods to set and inspect
header information, content, and attachments.
To send e-mail, you use the Mail method.
List of Email methods contains a list of all the methods in the Email class.
SMTP examples
Examples follow in which Email objects are used to create and send a request to an SMTP server. No Janus port definitions are shown. For comments about defining Janus ports for the SMTP Helper, see the earlier remarks.
Basic e-mail example
This example uses most of the Email methods to send a simple message
to three recipients.
The local CLSOCK port used is named SPAM
.
b %letter object Email %h longstring %t longstring %name longstring %nick string len 64 %letter = new %name = 'C_Coolidge@presidents.usa' %nick = 'SilentCal' %letter:AddRecipient(%name, %nick) %name = 'D_Eisenhower@presidents.usa' %nick = 'Ike' %letter:AddCc(%name, %nick) %name = L_Johnson@presidents.usa' %nick = 'LBJ' %letter:AddBcc(%name, %nick) %letter:Sender('a_huckster@bankandtrustme.com') %h = 'Subject:' %t = 'Lower Mortgage Rates' %letter:AddHeader(%h, %t) %h = 'Great deal of debt for you!' %letter:SetBody(%h) %letter:mail('SPAM', 0) print %letter:GetReplyCode with ' - ' with - %letter:GetReplyText %letter:discard end
E-mail with attachment
In the following example, an image is attached to a short e-mail message. The attachment is produced from a member of a local Model 204 procedure file using StringList class methods.
b %rolex is object Email %sl is object Stringlist %procdata is object Stringlist %jpg longstring %t longstring %temp string len 255 %procfile string len 10 %procname string len 63 %q float %rc float %rolex = new %sl = new %t = 'jbgood@netscape.net' %rolex:AddRecipient(%t, 'JB') %t = 'cberry@ucantbee-sirius.com' %rolex:Sender(%t) %rolex:AddHeader('Subject:', 'watch this...') text to %sl I want an authentic imitation Rolex watch. Something like the one shown in this image. Know anyone who's got one? end text %rolex:SetBody(%sl, encoding='none', type='text/plain') %procfile = 'MYPROC' %procname = 'FAKE5.JPG' %rc = $procopn(%procname, %procfile) if %rc ne 0 then print 'Cant open procedure ' with %procname - with ' in file ' with %procfile with ', rc = ' - with %rc stop end if %procdata = new %procdata:appendOpenProcedure %jpg = %procData:binaryProcedureDecode %rolex:AddPart(%jpg, type='image/jpg', name='Rolex1.jpg') print %rolex:mail('MYSMTP', 0) ' is return from Mail method' print %rolex:GetReplyCode ' is return from GetReplyCode' print %rolex:GetReplyText %rolex:discard end
If the request is successful, results like the following display at the terminal:
0 is return from Mail method 221 is return from GetReplyCode ucantbee-sirius.com running IBM VM SMTP Level 320 closing connection