Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
smtp-connection
Advanced tools
The smtp-connection npm package is a low-level module for handling SMTP (Simple Mail Transfer Protocol) connections. It allows you to connect to an SMTP server, authenticate, and send emails. This package is useful for developers who need fine-grained control over the SMTP communication process.
Connecting to an SMTP Server
This feature allows you to establish a connection to an SMTP server. You can specify the host, port, and whether to use a secure connection.
const SMTPConnection = require('smtp-connection');
const connection = new SMTPConnection({
host: 'smtp.example.com',
port: 587,
secure: false
});
connection.connect(function(err) {
if (err) {
console.error('Connection error:', err);
} else {
console.log('Connected to SMTP server');
}
});
Authenticating with the SMTP Server
This feature allows you to authenticate with the SMTP server using a username and password.
connection.login({
user: 'username',
pass: 'password'
}, function(err) {
if (err) {
console.error('Authentication error:', err);
} else {
console.log('Authenticated successfully');
}
});
Sending an Email
This feature allows you to send an email through the connected and authenticated SMTP server. You can specify the sender, recipient, subject, and body of the email.
const message = {
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'Test Email',
text: 'Hello, this is a test email.'
};
connection.send({
from: message.from,
to: message.to
}, message, function(err, info) {
if (err) {
console.error('Send error:', err);
} else {
console.log('Email sent:', info);
}
});
Nodemailer is a higher-level module for sending emails using various transport methods, including SMTP. It provides a simpler API and more features out of the box compared to smtp-connection, such as support for HTML content, attachments, and various authentication methods.
EmailJS is another package for sending emails via SMTP. It offers a straightforward API and supports features like attachments and HTML content. It is similar to Nodemailer but with a slightly different API design.
SMTP-Client is a low-level SMTP client similar to smtp-connection. It provides fine-grained control over the SMTP communication process but with a different API design. It is suitable for developers who need detailed control over the SMTP protocol.
Connect to SMTP servers
This is a fork of simplesmtp. Includes only the client and nothing more. API is simplified and should be easier to use.
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
If 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.quite();
Use it for less graceful disconnect
connection.close();
MIT
FAQs
Connect to SMTP servers
The npm package smtp-connection receives a total of 45,767 weekly downloads. As such, smtp-connection popularity was classified as popular.
We found that smtp-connection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.