Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
versa-mail
Advanced tools
Readme
This emailing package is a Node.js library that simplifies sending emails using either Nodemailer or Azure Communication Services. It provides easy-to-use functions to send single or bulk emails with customizable templates and attachments.
To use the Emailer package in your Node.js project, you can install it via npm:
npm install versa-mail
The Emailer package allows you to create a mailer instance based on the mailer type you want to use. The mailer factory class provides a convenient method for this purpose.
const MailerFactory = require("versa-mail");
// Configuration for Nodemailer mailer
const nodemailerConfig = {
emailService: "your_email_service_provider",
emailUsername: "your_email_username",
emailPassword: "your_email_password",
senderAddress: "your_sender_email@example.com",
};
// Configuration for Azure mailer
const azureConfig = {
connectionString: "your_azure_connection_string",
senderAddress: "your_sender_email@example.com",
};
// Create the mailer instance based on the selected type
const mailerType = "nodemailer"; // Use "nodemailer" for Nodemailer or "azure" for Azure Email Service
const mailerFactory = new MailerFactory();
const mailer = mailerFactory.createMailer(mailerType, nodemailerConfig);
// OR
const mailer = mailerFactory.createMailer("azure", azureConfig);
You can send a single email using the sendEmail
method. The method allows you to use custom or default email templates, replace template variables, and include attachments.
const emailOptions = {
withDefaultTemplate: true, // Set to false if using a custom template
templateName: "template_name", // Required if withDefaultTemplate is true
template: "<html><body>Hello, #{username}!</body></html>", // Required if withDefaultTemplate is false
constants: {
username: "John Doe", // Replace #{username} in the template with this value
},
subject: "Test Email",
email: "recipient@example.com",
replyTo: "reply@example.com", // Optional
cc: ["cc_recipient1@example.com", "cc_recipient2@example.com"], // Optional
bcc: ["bcc_recipient1@example.com", "bcc_recipient2@example.com"], // Optional
attachments: [
{
name: "attachment.txt",
url: "path.to.attachment.",
},
], // Optional
};
mailer
.sendEmail(emailOptions)
.then((response) => {
// Email sent successfully
console.log("Email sent successfully:", response);
})
.catch((error) => {
// Error sending email
console.error("Error sending email:", error);
});
OR;
try {
const sendMail = await mailer.sendEmail(emailOptions);
console.log("Email sent successfully:", sendMail);
} catch (err) {
console.error("Error sending email:", err);
}
If you need to send bulk emails, you can use the sendBulk
method. This method allows you to customize each email for individual recipients and include common attachments for all emails.
const bulkEmailOptions = {
withDefaultTemplate: true, // Set to false if using a custom template
templateName: "template_name", // Required if withDefaultTemplate is true
template: "<html><body>Hello, #{username}!</body></html>", // Required if withDefaultTemplate is false
constants: {
// Common constants for all emails
company: "Your Company",
website: "https://example.com",
},
subject: "Test Email",
users: [
{
//An object of user specific constants to replace placeholders within the html. User specific Attachments can be handled seperately.
email: "recipient1@example.com",
username: "Recipient 1",
attachments: [
{
name: "attachment1.txt",
url: "path/to/attachment1.txt",
},
], // Optional
},
{
email: "recipient2@example.com",
username: "Recipient 2",
// Add more user-specific options here
},
],
cc: ["cc_recipient@example.com"], // Optional
bcc: ["bcc_recipient@example.com"], // Optional
attachments: [
{
name: "common_attachment.txt",
url: "path/to/common_attachment.txt", //should a valid CDN link
},
], // Optional
};
mailer
.sendBulk(bulkEmailOptions)
.then((response) => {
// Bulk emails sent successfully
console.log("Bulk emails sent:", response);
})
.catch((error) => {
// Error sending bulk emails
console.error("Error sending bulk emails:", error);
});
If you are using the AzureMailer
, you have the option to customize email templates with CSS configurations. The following CSS configurations are available:
To set CSS configurations, provide an object with these properties when creating the AzureMailer
instance.
const cssConfigurations = {
USER_DEFINED_BODY_CSS: "body { background-color: #f0f0f0; }",
USER_DEFINED_CONTAINER_CSS: ".container { padding: 20px; }",
USER_DEFINED_H1_CSS: "h1 { color: #0080ff; }",
};
const mailer = new AzureMailer(
connectionString,
senderAddress,
cssConfigurations
);
email
and username
fields in the email options are mandatory and must be valid strings.Feel free to reach out to us if you encounter any issues or have questions about using the Emailer package! Happy emailing!
FAQs
Multi-Client email api
The npm package versa-mail receives a total of 1 weekly downloads. As such, versa-mail popularity was classified as not popular.
We found that versa-mail demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.