ibmcatalyst-smtpmailer
v1.0.0
Published
a nodejs module that send an email using SMTP protocol
Downloads
1
Readme
Overview
This module provides a utility class and methods to send an email using smtp protocol.
Prerequisites
Note: On Windows you should run all commands from Git Bash window
- Install Git client.
Note: When installing, please select the option to use Git from the Windows command line
Note: It is very important that you add an SSH Key to your Gitlab profile, or you will not be able to securely download projects.
- Generate an SSH key and then upload the key here.
Note: It is important that you use Git Bash if you are using Windows to run the commands listed in the Generating SSH Keys instructions.
- Install node.js
Install
Run the following command to install:
$ npm install ibmcatalyst-smtpmailer
Methods
var mailer = require("ibmcatalyst-smtpmailer");
var smtpReq = mailer(params, callback);
Send an email with configuration parameters
params
.An optional callback
callback(err, smtpReq)
will fire once the initial handshake is complete.The smtpReq object is a stream.
Use
smtpReq.setHeader(key, value)
to set the'content-type'
,'subject'
, and such things relevant to emails.Use
smtpReq.removeHeader(key)
to remove a header.Use
smtpReq.write(data)
to write a string or a buffer to the message body after the headers.Use
smtpReq.end(data)
to transmit data.
Example
var smtpmailer = require("ibmcatalyst-smtpmailer");
function sendEmail(options){
var mail = smtpmailer({
host : options.host,
port : options.port,
from : options.from,
to : options.to
});
mail.setHeader("content-type", "text/plain");
mail.setHeader("subject", options.subject);
mail.end(options.body);
}
var params = {
host: "relay.us.ibm.com",
port: 25,
from: "[email protected]",
to: "[email protected]",
subject: "Greeting message",
body: "Hi buddy, how are you doing?"
};
sendEmail(params);
Troubleshooting
If you are repeatedly prompted for a password, your SSH agent may not be running or configured correctly. This is usually an issue on Windows. Do the following (from Git Bash on Windows) to ensure that the agent is started and has your identity added to it. You should see the text you uploaded to your SSH Keys section in Gitlab from the second command.
$ eval "$(ssh-agent -s)" $ ssh-add -L
If not, you need to do issue the following commands. Keep Git Bash open on Windows to avoid further password prompts.
```c
$ ssh-add ~/.ssh/id_rsa
$ ssh-add -L