Sendmail without setting up SMTP server

npm install sendmail
var sendmail = require(sendmail)({
  logger: {
    debug: console.log,
    info: console.info,
    warn: console.warn,
    error: console.error
  },
  silent: false
})
  • logger customized logger.
  • silent silent mode
var sendmail = require(sendmail)();
 
sendmail({
    from: no-reply@yourdomain.com,
    to: test@qq.com, test@sohu.com, test@163.com ,
    subject: test sendmail,
    html: Mail of test sendmail ,
  }, function(err, reply) {
    console.log(err && err.stack);
    console.dir(reply);
});

Mail is build with mailcomposer.

The following are the possible fields of an e-mail message:

  • from – The e-mail address of the sender. All e-mail addresses can be plain 'sender@server.com' or formatted 'Sender Name <sender@server.com>', see here for details
  • sender – An e-mail address that will appear on the Sender: field
  • to – Comma separated list or an array of recipients e-mail addresses that will appear on the To: field
  • cc – Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field
  • bcc – Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field
  • replyTo – An e-mail address that will appear on the Reply-To: field
  • inReplyTo – The message-id this message is replying
  • references – Message-id list (an array or space separated string)
  • subject – The subject of the e-mail
  • text – The plaintext version of the message as an Unicode string, Buffer, Stream or an object {path: ‘…’}
  • html – The HTML version of the message as an Unicode string, Buffer, Stream or an object {path: ‘…’}
  • watchHtml – Apple Watch specific HTML version of the message, same usage as with text and html
  • icalEvent – iCalendar event, same usage as with text and html. Event method attribute defaults to ‘PUBLISH’ or define it yourself: {method: 'REQUEST', content: iCalString}. This value is added as an additional alternative to html or text. Only utf-8 content is allowed
  • headers – An object or array of additional header fields (e.g. {“X-Key-Name”: “key value”} or [{key: “X-Key-Name”, value: “val1”}, {key: “X-Key-Name”, value: “val2”}])
  • attachments – An array of attachment objects (see below for details)
  • alternatives – An array of alternative text contents (in addition to text and html parts) (see below for details)
  • envelope – optional SMTP envelope, if auto generated envelope is not suitable (see below for details)
  • messageId – optional Message-Id value, random value will be generated if not set
  • date – optional Date value, current UTC string will be used if not set
  • encoding – optional transfer encoding for the textual parts
  • raw – if set then overwrites entire message output with this value. The value is not parsed, so you should still set address headers or the envelope value for the message to work
  • textEncoding – set explicitly which encoding to use for text parts (quoted-printable or base64). If not set then encoding is detected from text content (mostly ascii means quoted-printable, otherwise base64)

All text fields (e-mail addresses, plaintext body, html body) use UTF-8 as the encoding. Attachments are streamed as binary.

Attachment object consists of the following properties:

  • filename – filename to be reported as the name of the attached file, use of unicode is allowed. If you do not want to use a filename, set this value as false, otherwise a filename is generated automatically
  • cid – optional content id for using inline images in HTML message source. Using cid sets the default contentDisposition to 'inline' and moves the attachment into a multipart/related mime node, so use it only if you actually want to use this attachment as an embedded image
  • content – String, Buffer or a Stream contents for the attachment
  • encoding – If set and content is string, then encodes the content to a Buffer using the specified encoding. Example values: base64, hex, binary etc. Useful if you want to use binary attachments in a JSON formatted e-mail object
  • path – path to a file or an URL (data uris are allowed as well) if you want to stream the file instead of including it (better for larger attachments)
  • contentType – optional content type for the attachment, if not set will be derived from the filename property
  • contentTransferEncoding – optional transfer encoding for the attachment, if not set it will be derived from the contentType property. Example values: quoted-printable, base64
  • contentDisposition – optional content disposition type for the attachment, defaults to ‘attachment’
  • headers is an object of additional headers, similar to message.headers option {'X-My-Header': 'value'}
  • raw is an optional value that overrides entire node content in the mime message. If used then all other options set for this node are ignored. The value is either a string, a buffer, a stream or an attachment-like object (eg. provides path or content)

Share this Project