0.2.1 • Published 8 years ago
sfn-mail v0.2.1
SFN-Mail
Simple Friendly Node.js Mail client for sending messages.
This package is a simple wrapper for Nodemailer.
Install
npm install sfn-emailExample
const Mail = require("sfn-email");
Mail.init({
host: "smtp.mail.qq.com",
port: 25,
from: "xxxxxxxx@qq.com",
auth: {
username: "xxxxxxxx@qq.com",
password: "xxxxxxxx",
}
});
(async() => {
var mail = new Mail("A test email");
mail.to("1402289104@qq.com")
.text("Text content");
try {
var res = await mail.send();
console.log(res);
} catch (e) {
console.log(e);
}
console.log(mail);
})();API
Mail.init(options: object)Initiates email transport configurations.optionsTransport configurations for Nodemailer, may carry afromproperty sets the default from address. Other options, please check https://nodemailer.com/smtp/.
new Mail(options: object)new Mail(subject: string, options?: object)Creates a new email with a specified subject.subjectEmail subject, optionally you can ignore this argument, just set theoptions, and set the subject in the options.optionsTransport configurations for Nodemailer, may carry afromproperty sets the from address, and atoproperty sets a receiver or receivers, and an optionalsubjectif you don't pass it as an argument.
mail.from(address: string)Sets the sender address.mail.to(...address: string[])Sets receiver addresses, optionally you can call this method multiple times to concatenate addresses.mail.cc(...address: string[])Sets receiver addresses on the CC field, optionally you can call this method multiple times to concatenate addresses.mail.cc(...address: string[])Sets receiver addresses on the BCC field, optionally you can call this method multiple times to concatenate addresses.mail.text(content: string)Sets the plain text version of the email.mail.html(content: string)Sets the HTML version of the email.mail.attchment(filename: string)Sets a file as an attachment sent with the email, optionally you can call this method multiple times to attach multiple files.mail.header(field: string, value: string | number | Date)Sets a header field sent with the email, optionally you can call this method multiple times to set multiple fields.mail.send(): PromiseSends the email to all recipients. Returns a Promise, the only argument passed to the callback ofthen()is an object which may carry information like:messageIdthe final Message-Id value;envelopethe envelope object for the message;acceptedrecipient addresses that were accepted by the server;rejectedrecipient addresses that were rejected by the server;pendingrecipient addresses that were temporarily rejected; together with the server response;responsethe last SMTP response from the server.