This is a transport written to implement mailgun-js with winston
npm install winston npm install winston-mailgun
var winston = require('winston'); require('winston-mailgun').MailGun; winston.add(winston.transports.MailGun, options);
Winston MailGun accepts similar options as mailgun-js
Required:
apiKey
Your Mailgun API KEYdomain
Your Mailgun Domainto
The email address(es) to receive e-mail
Optional:
from
The address you want to send from. (default: winston@[server-host-name])subject
Subject of e-maillevel
Level that this transport should log (e-mail).silent
Boolean flag indicating whether to suppress output and thus, the e-mail.proxy
The proxy URI in format http[s]://[auth@]host:port. ex: 'http://proxy.example.com:8080'timeout
Request timeout in milliseconds
Please see Mailgun Attachments and below examples.
You can send attachments the same way you normally would using mailgun-js. Simply pass an object into your meta-data with the property attachment
.
var logger = require('winston');
require('winston-mailgun').MailGun;
var options = {
apiKey: <your api key>,
domain: <your domain>,
to: [email protected],
from: [email protected],
subject: 'This is a Test Email',
level: 'notify'
}
winston.add(winston.transports.MailGun, options);
var filename = 'mailgun_logo.png';
var filepath = path.join(__dirname, filename);
var fileStream = fs.createReadStream(filepath);
var fileStat = fs.statSync(filepath);
var attachment = {
data: fileStream,
filename: 'my_custom_name.png',
knownLength: fileStat.size,
contentType: 'image/png'
}
// To send an attachment with meta data (usually to send images)
logger.notify('This will be in the body of your email.', {
attachment: attachment
});
// To send a normal file (no need for meta data, you can just use a string)
logger.notify('This will be in the body of your email.', {
attachment: __dirname + '/' + filename
});
// No attachment, you just want to e-mail the objects in the body of the email
var testObject = {
"id": 123123,
"message": "This important thing needs to be e-mailed!"
}
logger.notify('This will be in the body of your email.', testObject)
// NOTE: If your object contains the property 'attachment', but
// the attachment object does not contain 'data', the object will
// just simply be appended to the body of your e-mail.
// Will NOT result in an e-mail with attachment
var testObject = {
"attachment": "unknown",
"test": "Email"
}
logger.notify('This will be in the body of your email.', testObject)
The MIT License (MIT)
Copyright (c) 2015 Josh Madewell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.