pnuts.mail module

This module is used for sending emails from Pnuts scripts. The Java Mail API is required to use this module.

Sending Email

sendEmail ( Map map ) or
( mailhost, subject, content, from, to {, cc, bcc, replyTo, charset } )

sendEmail() sends an email. If a Map object is specified, the following keys are used.

Key Value
mailhost String (if null, "localhost" is used instead)
subject String
content MimeMultipart, MimeBodyPart String, File, URL, or Array/Collection/Generator of those objects.
charset String
from String or InternetAddress
to InternetAddress, String, or Array/Collection/Generator of those objects.
cc InternetAddress, String, or Array/Collection/Generator of those objects.
bcc InternetAddress, String, or Array/Collection/Generator of those objects.
replyTo InternetAddress, String, or Array/Collection/Generator of those objects.
userid String
password String
ssl boolean
e.g.
sendEmail("mailhost", "subject", "Hello!", "myname", "friends")
m = map()
m.mailhost = "foo.bar.com"
m.subject = "test"
m.from = "myname"
m.to = "friends"
m.content = "Hello!"
sendEmail(m)
emailAddress ( String address { , String personal_information } )

emailAddress() makes an InternetAddress object from address and optional personal_information. If personal_information includes any non-ASCII character, appropriate charset must be registerred with setMailCharset() before the emailAddress() call.

emailAddress("foo@bar.com", "whoever")
setMailCharset ( String charset )

setMailCharset() registers the default charset for email content, subject, and personal information of email addresses.

mimepart ( Object content, String mimeType )

mimepart() makes a MimeBodyPart object from content and mimeType.

html = mimepart("<html>...</html>", "text/html")

Receiving Email

openMailStore (URL url {, properties } ) or
(String protocol, String host, String userid, String password {, properties } )

openMailStore() opens a mail store specifying a URL or a set of necessary information to open the store.

store = openMailStore("imap", "mailhost", "id", "pass")
openMailFolder (Store store, String folderName)

openMailFolder() opens a mail folder.

folder = openMailFolder(store, "INBOX")
getMessages (Folder folder {, FetchProfile.Item[] fetchProfile { , Message[] messages } } )

getMessages() creates an array of Message objects of the specified mail folder.

If fetchProfile is not null, the corresponding mail headers are prefetched.

The following variables are convenient when specifying the fetchProfile.

FETCH_ENVELOPE
From, To, Cc, Bcc, ReplyTo, Subject and Date. See FetchProfile$Item::ENVELOPE.
FETCH_CONTENT_INFO
ContentType, ContentDisposition, ContentDescription, Size and LineCount. See FetchProfile$Item::CONTENT_INFO.
FETCH_FLAGS
See FetchProfile$Item::FLAGS.

The default value of fetchProfile is [FETCH_FLAGS, FETCH_ENVELOPE].

messages = getMessages(folder)

messages = getMessages(folder, [FETCH_ENVELOPE, FETCH_FLAGS, FETCH_CONTENT_INFO])
listMailFolders (Folder folder, callback(folder) {, enterFunc() , exitFunc() } )

listMailFolders() traverses the folder hierarchy from the specified mail folder as the root and calls the callback function. When enterFunc() and exitFunc() are specified, they are called when the traversal enters/exits a subfolder.

listMailFolders(folder, println)