Documentation of Meteor's email API.
The email
package allows sending email from a Meteor app. To use it, add thepackage to your project by running in your terminal:
meteor add email
The server reads from the MAILURL
environment variable to determine how tosend mail. The MAIL_URL
should reference anSMTP server anduse the form smtp://USERNAME:PASSWORD@HOST:PORT
orsmtps://USERNAME:PASSWORD@HOST:PORT
. The smtps://
form (the s
is for“secure”) should be used if the mail server requires TLS/SSL (and does not useSTARTTLS
) and is most common on port 465. Connections which start unencryptedprior to being upgraded to TLS/SSL (using STARTTLS
) typically use port 587(and _sometimes 25) and should use smtp://
. For more information see theNodemailer docs
If MAIL_URL
is not set, Email.send
outputs the message to standard outputinstead.
Server
Email.send(options)
import { Email } from 'meteor/email' (email/email.js, line 145)
Send an email. Throws an Error
on failure to contact mail serveror if mail server returns an error. All fields should matchRFC5322 specification.
If the MAIL_URL
environment variable is set, actually sends the email.Otherwise, prints the contents of the email to standard out.
Note that this package is based on mailcomposer 4, so make sure to refer tothe documentationfor that version when using the attachments
or mailComposer
options.
Options
- fromString
"From:" address (required)
to, cc, bcc, replyToString or Array of Strings
"To:", "Cc:", "Bcc:", and "Reply-To:" addresses
inReplyToString
Message-ID this message is replying to
referencesString or Array of Strings
Array (or space-separated string) of Message-IDs to refer to
messageIdString
Message-ID for this message; otherwise, will be set to a random value
subjectString
"Subject:" line
text, htmlString
Mail body (in plain text and/or HTML)
watchHtmlString
Mail body in HTML specific for Apple Watch
icalEventString
iCalendar event attachment
headersObject
Dictionary of custom headers - e.g.
{ "header name": "header value" }
. To set an object under a header name, useJSON.stringify
- e.g.{ "header name": JSON.stringify({ tracking: { level: 'full' } }) }
.attachmentsArray of Objects
Array of attachment objects, asdescribed in the mailcomposer documentation.
mailComposerMailComposer
- A MailComposerobject representing the message to be sent. Overrides all other options.You can create a
MailComposer
object vianew EmailInternals.NpmModules.mailcomposer.module
.
You must provide the from
option and at least one of to
, cc
, and bcc
;all other options are optional.
Email.send
only works on the server. Here is an example of how aclient could use a server method call to send an email. (In an actualapplication, you’d need to be careful to limit the emails that aclient could send, to prevent your server from being used as a relayby spammers.)
// Server: Define a method that the client can call.
Meteor.methods({
sendEmail(to, from, subject, text) {
// Make sure that all arguments are strings.
check([to, from, subject, text], [String]);
// Let other method calls from the same client start running, without
// waiting for the email sending to complete.
this.unblock();
Email.send({ to, from, subject, text });
}
});
// Client: Asynchronously send an email.
Meteor.call(
'sendEmail',
'Alice <alice@example.com>',
'bob@example.com',
'Hello from Meteor!',
'This is a test of Email.send.'
);