var Mail = require('Mail').Mail;
var message = new Mail();
Interface for sending email messages from SilkJS programs.
This class provides support for encoding and sending multipart email messages. You can use this class to send HTML email, email with attachments, etc.
var message = new Mail();
message.setFrom(from);
message.addTo(to);
message.setSubject(subject);
message.setHtml('<h1>Test Message</h1>');
message.addAttachment('foo', 'text/plain', fs.readFile64('/tmp/foo'));
message.send();
This class relies on the command-line sendmail program.
It is located in /usr/sbin/sendmail on OSX, but must be installed on Linux using your package management software (e.g. apt, yum, rpm, etc.)
var message = new Mail();
Create instance of mail message.
The message is not sent until you call message.send(). Before you send the message, you will typically set at least the to, subject, and text parts of the message.
message.setFrom(from); // e.g. from = 'me@example.com'
Set from: field for message.
message.setTo(to); // e.g. to = 'you@example.com'
Set to: field for message (e.g. recipient's email address).
Note that an email message may have multiple recipients. This function clears the recipient list and sets it to the one email address you provide.
See Mail.addTo() for a method to add additional recpient email addresses to the to: field.
message.addTo(to); // e.g. to = 'you@example.com'
Add recipient to the to: field for message (e.g. recipient's email address).
Note that an email message may have multiple recipients. This function adds the recipient to the to: list.
See Mail.setTo() for a method to reset the to: field to an initial single recipient
message.setCc(cc); // e.g. cc = 'you@example.com'
Set cc: field for message (e.g. recipient's email address).
Note that an email message may have multiple recipients. This function clears the cc list and sets it to the one email address you provide.
See Mail.addCc() for a method to add additional recipient email addresses to the cc: field.
message.addCc(cc); // e.g. cc = 'you@example.com'
Add recipient to the cc: field for message (e.g. recipient's email address).
Note that an email message may have multiple recipients. This function adds the recipient to the cc: list.
See Mail.setCc() for a method to reset the cc: field to an initial single recipient
message.setBcc(bcc); // e.g. bcc = 'you@example.com'
Set bcc: field for message (e.g. recipient's email address).
Note that an email message may have multiple recipients. This function clears the bcc list and sets it to the one email address you provide.
See Mail.addBcc() for a method to add additional recipient email addresses to the bcc: field.
message.addBcc(bcc); // e.g. bcc = 'you@example.com'
Add recipient to the bcc: field for message (e.g. recipient's email address).
Note that an email message may have multiple recipients. This function adds the recipient to the bcc: list.
See Mail.setBcc() for a method to reset the bcc: field to an initial single recipient
message.setSubject(subject);
Set the subject: field for the email message.
An email message can have only one subject: field.
message.setText(text);
This function sets the text part of the email message.
Email messages do not have to be multipart MIME - they can be plain text.
For a MIME message, typically containing at least an HTML body, you should set a text body as well. This is so people who have email clients that do not support HTML will be able to display a plain text version of the message body.
For a plain text message, you will only need to set the text part. Or if you do not set an HTML part, the recipient will see the plain text version, but will also be able to manage any attachments you add to the message.
See Message.setHtml() for a method to set the HTML part, and Message.addAttachment() for adding attachment parts.
message.setHtml(html);
This function sets the HTML part of the email message.
Email messages do not have to be multipart MIME - they can be plain text.
For a MIME message, typically containing at least an HTML body, you should set a text body as well. This is so people who have email clients that do not support HTML will be able to display a plain text version of the message body.
For a plain text message, you will only need to set the text part. Or if you do not set an HTML part, the recipient will see the plain text version, but will also be able to manage any attachments you add to the message.
See Message.setText() for a method to set the text part, and Message.addAttachment() for adding attachment parts.
message.addAttachment(filename, contentType, body);
Add an attachment to an email message.
Email messages may contain multiple attachment parts. Use this function to add one attachment at a time to your email message.
While it is possible to send binary attachments in binary form, JavaScript does not have a built-in binary type. As with many of the SilkJS libraries, this class deals with binary as base64 encoded strings; thus your attachments must be base64 encoded.
message.send();
Sends the email message.
This function actually formats the multipart MIME email message, writes it to a file in /tmp, and invokes your system's sendmail program to send the message.
You should have set the to:, subject:, and text of the message, at least, before calling this function.'
This function does not provide any indication of whether the email was actually sent, if the sendmail binary could be found on the system, etc.