Documentation generated by XL CLAIRE v3.3.37 at Fri, 17 Nov 2006
| categories Class model |
An email object is described by parts organised into a hierarchy.
The email class contain a mainpart slot that can be used to inspect
the part hierarchy. Parts are either single (singlepart) providing
a data slot of type port or multiple (multipart) providing a subparts
slot containing children parts. All parts have their own mime headers
that are handled with the bracket notation. For instance here is a
simple method that dumps the part hierarchy of a message :
dump_parts(e:Mail/email) : void ->
dump_parts(e.Mail/mainpart, "")
dump_parts(p:Mail/singlepart, indent:string) : void ->
printf("~ASingle part (~A)\n", indent, e["Content-Type"])
dump_parts(p:Mail/multipart, indent:string) : void ->
printf("~AMulti part (~A)\n~I", e["Content-Type"],
for sp in p.Mail/subparts
dump_parts(sp, indent /+ " "))
| categories Creating new messages |
The mail module uses the object 'email' to represent an email
message. The email! method family is used to create a new instance of
email. For instance let's create a new message with a single recipient :
Mail headers are handled using the bracket notation, for instance :
msg :: Mail/email!("sbenilan@claire-language.com", "someone@somedomain.com")
Notice that by default headers "Mime-Version", "Date", "Message-ID",
"X-Mailer" are set automatically.
(msg["Subject"] := "[claire] Mail module is quite nice")
| categories Submitting content |
Once we have a message instance we may submit a content. The Mail module is intended to provide a convenient way for such a task and encourage the user to use the Wcl syntax within a redirection scope introduced by a balance usage of print_in_xxx/end_of_part methods. The end_of_part method would return a so called part object, the user should be familiar with the hierarchical structure of parts.
In order to illustrate the usage of print_in_xxx/en_of_part here is a quite
complete sample that creates a message embedding an attached document and
composed of two alternatives, a plain text alternative and an HTML alternative
that refers to an attached image :
msg :: Mail/email!("sbenilan@claire-language.com", "someone@somedomain.com")
(msg["Subject"] := "Annual activity report", // fill in the subject
Mail/print_in_related(msg),
Mail/print_in_alternative(msg), // we'll define both text and HTML alternative
// the text alternative
Mail/print_in_email(msg, "text/plain; charset=ISO-8859-1"),
?>Dear collaborator, please consult our annual report attached to this message<?
Mail/end_of_part(e),
// the HTML alternative with a logo image
Mail/print_in_email(msg, "text/html; charset=ISO-8859-1"),
?><img src="cid:logo"><br>
Dear collaborator,<br>
please consult our annual report attached to this message<?
Mail/end_of_part(msg),
Mail/end_of_part(msg),
// here we attach the logo image
let att := Mail/add_attachment(msg, "/path/to/logo.png", "image/png")
in att["Content-ID"] := "logo",
// here we attach the PDF document
Mail/add_attachment(msg, "/path/to/annual_report.pdf", "application/pdf"),
Mail/end_of_part(msg))
| categories Sending message through SMTP |
Once a message has been properly filled we may send the message through
SMTP using the smtp_send method. Unless smtp_from is specified the "From"
header of the message will be used to identify the sender with the SMTP
server. For instance :
(Mail/send(msg, "mailhost.somedomain.com"))
| categories Reading rough message |
The Mail module also provide a way to create a message from a rough content that should be supplied (as a readable port) to email!. One can inspect message headers using bracket notation and also inspect its parts with the email object.
| categories | Submitting content | normal dispatch | Mail method |
equivalent to add_attachment(self, src, fname, content-type) where fname has been constructed as the last path component of src.
| categories | Submitting content | normal dispatch | Mail method |
add_attachment returns a new part added to the given email. it is convenient for attached document or a related image. In the latter case a Content-ID header may be defined such to link related parts.
A "Content-Disposition" header is automatically added to the attachment part and set as inline and specifying fname as the file name that should be used for the image.