|
%!s(int64=5) %!d(string=hai) anos | |
---|---|---|
.. | ||
src | %!s(int64=5) %!d(string=hai) anos | |
.jshintrc | %!s(int64=5) %!d(string=hai) anos | |
.npmignore | %!s(int64=5) %!d(string=hai) anos | |
CHANGELOG.md | %!s(int64=5) %!d(string=hai) anos | |
Gruntfile.js | %!s(int64=5) %!d(string=hai) anos | |
LICENSE | %!s(int64=5) %!d(string=hai) anos | |
README.md | %!s(int64=5) %!d(string=hai) anos | |
package.json | %!s(int64=5) %!d(string=hai) anos |
SMTP client module. Connect to SMTP servers and send mail with it.
This module is the successor for the client part of the (now deprecated) SMTP module simplesmtp. For matching SMTP server see smtp-server.
Install with npm
npm install smtp-connection
Require in your script
var SMTPConnection = require('smtp-connection');
var connection = new SMTPConnection(options);
Where
true
) or not (if false
)SMTPConnection instances are event emitters with the following events
Establish the connection
connection.connect(callback)
Where
After the connect event the connection
has the following properties:
true
then the connection uses a TLS socket, otherwise it is using a cleartext socket. Connection can start out as cleartext but if available (or requireTLS
is set to true) connection upgrade is triedIf the server requires authentication you can login with
connection.login(auth, callback)
Where
pass
and xoauth2
values are set) or an XOAuth2 token generator object.If a XOAuth2 token generator is used as the value for auth.xoauth2
then you do not need to set auth.user
. XOAuth2 generator generates required accessToken itself if it is missing or expired. In this case if the authentication fails, a new token is requeested and the authentication is retried. If it still fails, an error is returned.
XOAuth2 Example
var generator = require('xoauth2').createXOAuth2Generator({
user: '{username}',
clientId: '{Client ID}',
clientSecret: '{Client Secret}',
refreshToken: '{refresh-token}'
});
// listen for token updates
// you probably want to store these to a db
generator.on('token', function(token){
console.log('New token for %s: %s', token.user, token.accessToken);
});
// login
connection.login({
xoauth2: generator
}, callback);
Once the connection is authenticated (or just after connection is established if authentication is not required), you can send mail with
connection.send(envelope, message, callback)
Where
response
string (if available)Use it for graceful disconnect
connection.quit();
Use it for less graceful disconnect
connection.close();
MIT