Grunt task to run a MailDev mail server, to view and test emails during development.
You need node, npm, and grunt already installed.
npm install grunt-maildev --save-dev
Start a server, keep it running and open a browser on the web view:
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
grunt.initConfig({
maildev: {
run: {
keepAlive: true,
open: true
}
}
});
grunt.registerTask('default', ['maildev:run']);
Start a server and use it for your tests (logging all received emails to console), then close everything:
grunt.initConfig({
maildev: {
test: {
onNewMail: function(email) {console.log(email);},
options: {
smtp: {
port: 1625
},
http: {
address: '0.0.0.0',
port: 1680,
user: 'user_login',
password: 'secret_password'
}
}
}
}
});
grunt.registerTask('test', ['maildev:test, test1, test2']);
Please refer to MailDev if you need more understanding regarding each option.
Also, note that the following options can also be specified directly at task level:
- keepAlive
- onNewMail
- open
Type: string
Default: 127.0.0.1
The IP address the HTTP server will listen to. Leave as is to restrict connections to local machine, or set to '0.0.0.0' (or public IP address) to accept connections from the outside world.
Type: string
Default: null
If set (in conjunction with http.user), http server will require authentication using supplied name and password.
Type: number
Default: 1080
The port for the webserver (to display emails received).
Type: string
Default: null
If set, http server will require authentication using supplied name and password.
Type: boolean
Default: false
If true, keep the server alive indefinitely. Any task specified after this will not run.
You do not want this if you have tests or watches set after this task!
Type: function
Default: null
If specified, will be called each time a message is received by the server, with the message passed as an argument.
See here for the fields of the supplied mail object.
Type: boolean
Default: false
If true, open a browser displaying the web server view.
Type: string
Default: 127.0.0.1
The IP address the SMTP server will listen to. Leave as is to restrict connections to local machine, or set to '0.0.0.0' (or public IP address) to accept connections from the outside world (not recommended).
Type: string
Default: null
If set (in conjunction with smtp.user), smtp server will require authentication using supplied name and password.
Type: number
Default: 1025
The port for the SMTP server.
Type: object
Default: null
Specifies if/how messages could be relayed to an actual SMTP server (more explanations).
Authorized fields:
smtp: {
relay: {
host: 'mail.yourdomain.com',
port: 465,
secure: true,
user: 'your_user',
pass: 'your secret password',
auto: 'filename or rules array see https://github.com/djfarrelly/MailDev#auto-relay-mode'
},
}
Type: boolean
, string
or Array
Default: false
Specifies if auto-relay should be setup (see https://github.com/djfarrelly/MailDev#auto-relay-mode). If set to anything not falsy, it will switch on auto-relaying Acceptable values are:
- an array: should match the syntax described in https://github.com/djfarrelly/MailDev#auto-relay-mode
- a string: should be the name of a JSON file containing an array of relay rules as above
- anything else not falsy: will auto-relay all messages
Type: string
Default: null
If set, smtp server will require authentication using supplied name and password.
You need git
and node
git clone https://github.com/xavierpriour/grunt-maildev.git
cd grunt-maildev
npm install
grunt
Thanks and enjoy!
##Changelog
###2.1.0 (2015-08-26)
- updated to MailDev 0.12: set web IP separately from SMTP, and auto-relay options
###2.0.3-2.0.2 (2015-07-17)
Bugfix:
- mailserver did not start
###2.0.1 (2015-07-16)
Bugfix:
- merge task-level and target-level options
###2.0.0 (2015-07-16)
Features:
- updated to MailDev 0.11 and all its new options
- better options grouping
###1.0.1 (2015-04-17)
Features:
- Initial version
MIT © Xavier Priour