Postfix (Send Only) & Nodemailer for testing

What is Postfix?
It is Wietse Venema’s mail server that started life at IBM research as an alternative to the widely-used Sendmail program. Now at Google, Wietse continues to support Postfix.
Postfix attempts to be fast, easy to administer, and secure. The outside has a definite Sendmail-ish flavor, but the inside is completely different.

What is Nodemailer?
It is a module for Node.js applications to allow easy as cake email sending. The project got started back in 2010 when there was no sane option to send email messages, today it is the solution most Node.js users turn to by default.

Steps to install Postfix [OS: Ubuntu, Mint]

  • sudo apt update
  • sudo apt install mailutils (Select the following config)
    Select Internet Site from the menu, then press TAB to select <Ok>, then ENTER
  • sudo nano /etc/postfix/main.cf
    • mynetworks = 127.0.0.0/8 192.168.43.0/24 [::ffff:127.0.0.0]/104 [::1]/128
    • The above entry is required if you have Postfix installed on VM and you want to send emails from the host machine
  • sudo nano /etc/hostname
    • Create the above file and enter the hostname form which we wish to send the email, for example agami.com, it can be anything. Make sure to restart your machine for this to take effect
  • Restart the server after any config change 
    • sudo systemctl restart postfix 
  •  For checking delivery log: tail -f /var/log/mail.log
  • Use the following code to send email using nodemailer
const nodemailer = require(‘nodemailer’); 
async function main() {     
let transporter = nodemailer.createTransport({         
host: ‘127.0.0.1’,        
port: 25,        
secure: false,        
// auth: {        
//     user: ‘test@agami.com’,        
//     pass: ‘Secret’       
  // },        
tls: {             
rejectUnauthorized:false
        }    
});     
console.log(“Process Started To Send An Email”);     

for(i=0;i<1;i++)        
await transporter.sendMail({            
from: ‘babul@agami.com’,           
 to: ‘b007@getnada.com’,            
subject: ‘Hello ✔ ‘+i,            
  html: ‘<b>Helloworld!’+i+'</b>’       
 });     
console.log(‘Message sent ‘);

main().catch(console.error);

References:
http://www.postfix.org/
https://nodemailer.com/about/