xemail /
command and library to send email
git clone http://git.nthia.dev/xemail

cmd.js
index.js
lib/
readme.md
send.js

# xemail

command and module to send email with starttls and client certificate support

The command-line usage is similar to the sendemail command (which is a great tool),
but with client certificates and a few more options for setting raw aspects of the message.

# install

```
# to get the command-line tool:
git clone https://git.nthia.dev/xemail && cd xemail && ln -s $PWD/cmd.js ~/.local/bin/xemail

# to get the library:
mkdir -p node_modules && git clone https://git.nthia.dev/xemail node_modules/xemail
```

# usage

```
usage: cmd.js {OPTIONS...} (MSG_FILE|-)

Send an email message with the contents of MSG_FILE, stdin ("-"), -m, or --msg.

-f FROM, --from=FROM
-t TO, --to=TO

  Required arguments where FROM and TO are each email addresses.
  You can also format the addresses in the form "DISPLAY <ADDR@HOST>"
  which will set the appropriate header to set a display name
  different from the email address.

-s SERVER, --server=SERVER
-s SERVER:PORT, --server=SERVER:PORT
-p PORT, --port PORT
 
  Connect to an smtp SERVER on PORT (default 25).
  If a SERVER isn't explicitly given, it is derived from FROM.

-m MSG_LINE, --msg MSG_LINE

  Instead of reading from MSG_FILE or stdin, set lines of content from arguments.
  Each -m or --msg will add one line to the message body.

-H FIELD:VALUE, --header=FIELD:VALUE

  Add "FIELD: VALUE" to the set of headers.

--date=DATE

  Alias for --header=Date:DATE

--no-date

  Do not automatically set a Date header.

--utc

  Use UTC time for automatically sent Date headers.

--raw

  Do not send any headers and do not encode the payload.
  MSG_FILE is responsible for setting headers and encoding.

--cert=CERTFILE --key=KEYFILE

  Use a client-side tls certificate for the connection.

--ca=CAFILE

  Use a custom certificate to verify the remote server.

-k, --reject-unauthorized

  Do not validate the SSL certificate presented by the server.

-v, --version

  Print the versinn of this software. (1.0.0)

--help -h

  Show this message.

```

# api

``` js
const xemail = require('xemail')
const xemailSend = require('xemail/send')
```

## xemail(opts, cb)

Connect to an smtp server and send a message:

* `opts.from` - string of sender address
* `opts.to` - string of recipient address
* `opts.data` - string, Buffer, or readable stream of message contents to send
* `opts.server` - string smtp server address to connect to
* `opts.port` - numeric port of smtp server
* `opts.rejectUnauthorized` - if `true`, ignore invalid ssl certificate from the server
* `opts.key` - tls client certificate private key
* `opts.cert` - tls client certificate
* `opts.ca` - ca certificate to authenticate the remote server

`cb(err, sent, code)` fires with an error or the sent boolean status and final smtp code.

## let stream = xemailSend(opts, cb)

All the same options of `xemail()` but does not connect to a server.

Instead you are given a duplex `stream` that can be attached to any transport.

# license

public domain