Broad Network


Using Node Mailsend

Sending Email with ECMAScript – Part 3

ECMAScript 6

Foreword: In this part of the series I explain how to use the Node Mailsend module.

By: Chrysanthus Date Published: 15 Jul 2016

Introduction

This is part 3 of my series, Sending Email with ECMAScript. In this part of the series I explain how to use the Node Mailsend module. Written with ECMAScript in Node.js, this module can be used to send mail from any computer that has Node.js installed. It is a single file module and needs an ECMAScript program with the following variables and function, as you should use them.

const ms = require('./Mailsend.js');
This includes the mailsend module (assuming it is in the same directory as your program).

ms.setMAILFROM ('<bob@example.org>');
This variable must be coded with its email address. This is the address to which an email will be sent to, by the email server if an error occurs in the transmission. It can be the same as one of the addresses in the From field.

ms.setRecipientsArr(['<alice@example.com>','<theboss@example.com>']);
This array must be coded with at least one of the recipients' address.

ms.setFrom("'Bob Example' <bob@example.org>");
This variable must be coded with one or more email addresses, separated by commas, in a string. In this heading you have just one email address. It is for the person (or people) who wrote the email.

ms.setCc('<person@example.com>');
The use of this variable is optional. A copy of the email can be sent to the address (or addresses).

ms.setBcc('<police@theaudit.com>');
The use of this Blind Carbon Copy variable is optional.

ms.setSubject('A Test');
The use of this variable for the subject is obligatory.

ms.setBody("something sometning sometning");
The use of this variable, for the body of the letter is obligatory. The string value can be very long. The string should not have the dot between new lines.

ms.sendmail();
This function should be typed after the above has been typed. It sends the email to the email server (MSA, Mail Submission Agent), which sends the email to the destination. You can use the function as follows:

ms.sendmail(function(err, feedback)
    {
        if (err)
            console.log(err);
        else
            {
                console.log(feedback + ' Message has been sent.');
            }
    });

The argument to the sendmail() function is a callback function, with two parameters: err and feedback. If an error occurs, err has the error message, otherwise it is undefined. If the mail is sent to the MSA, then the value of feedback is Boolean true.

Installation
Installation is easy. Just download the free Mail Send program from the following link:

Node Mailsend

It comes as a zipped directory. Unzip the directory and you will find the file (module), Mailsend.js . Copy this file into the same directory as your ECMAScript program that has the above code.

Mailsend.js is a text file. Open the file with your text editor. Change the port and the domain name of your mail server from,

    const port = 587;
    const remoteHost = "localhost";

to something like,

    const port = 25;
    const remoteHost = "mail.o2online.de";

as necessary.

Save the file. That’s all.

Discussion
Any problem or suggestion or comments you have about the program should be done at the following group. You may need to subscribe (freely) first.

Discussion Group

That is it for this part of the series. We stop here and continue in the next part.

Chrys

Related Links

ECMAScript Basics
ECMAScript Operators
Expressions in ECMAScript
Statements in ECMAScript
Custom Objects in ECMAScript
Functions in ECMAScript
ECMAScript Date Object
The ECMAScript String Object
ECMAScript String Regular Expressions
ECMAScript Template Literal
The ECMAScript Array
ECMAScript Sets and Maps
ECMAScript Number
Scopes in ECMAScript
Mastering the ECMAScript (JavaScript) eval Function
Sending Email with ECMAScript
ECMAScript Insecurities and Prevention
Advanced Course
Advanced ECMAScript Regular Expressions
Promise in ECMAScript 2015
Generator in ECMAScript 2015
ECMAScript Module
More Related Links
Node Mailsend
EMySQL API
Node.js Web Development Course
Major in Website Design
Low Level Programming - Writing ECMAScript Module
ECMAScript Course

BACK NEXT

Comments

Become the Writer's Follower
Send the Writer a Message