smtp-reply

Parse and create SMTP Replies

Usage no npm install needed!

<script type="module">
  import smtpReply from 'https://cdn.skypack.dev/smtp-reply';
</script>

README

SMTP Reply

npm npm npm downloads build status

Install via npm

$ npm install smtp-reply

Usage

var SMTPReply = require( 'smtp-reply' )

Utilize the standard messages, only specifying a status code:

var reply = new SMTPReply( 220 )
// .toString() -> 
220 Service ready<CRLF>

Declaring a custom message:

var reply = new SMTPReply( 220, 'mx.domain.tld ESMTP' )
// .toString() ->
220 mx.domain.tld ESMTP<CRLF>

Enhancing the status code with RFC 1893 (Enhanced Mail System Status Codes):

var reply = new SMTPReply( 250, 1, 5, 'Flushed' )
// .toString() ->
250 2.1.5 Flushed<CRLF>

Multiline replies and everything else together:

var reply = new SMTPReply( 530, 5, 1, [
  'Authentication Required. Learn more at',
  'http://support.google.com/mail/bin/answer.py?answer=14257 ',
])
// .toString() ->
530-5.5.1 Authentication Required. Learn more at<CRLF>
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257<CRLF>

API

Reply.parse( input ) -> Reply

String input

Reply.getMessage( code, subject, detail ) -> String

Number code
Number subject (optional)
Number detail (optional)

new Reply( code, subject, detail, message )

Number code
Number subject (optional)
Number detail (optional)
String message (optional)

Properties:

  • code: Number, defauts to 0
  • subject: Number, defauts to 0
  • detail: Number, defauts to 0
  • lines: Array, defauts to []

Getters/Setters:

  • get/set message: String, defauts to ""
  • get/set enhancement: String, defauts to "0.0.0"

Methods:

  • parse( str ): Reply
    • String str
  • toString( legacy ): String
    • Boolean legacy (optional), defauts to false
  • set( code, subject, detail, message )
    • Number code
    • Number subject (optional)
    • Number detail (optional)
    • String message (optional)