Implications of Using SMTP Server when Sending Emails with Node.js - node.js

I want to send emails with my Node server. These are no-reply type emails, simply as reminders. The server will not need to handle incoming email. I know that there are services out there like Postmark, Mailchimp, etc. that will send emails for me, but I really do not want to pay for a service.
Using Nodemailer I have to specify a SMTP server. I can piggy back off of GMail or something but that's not desirable because the mail will not be coming from my domain (correct?).
But there is also node-sendmail which will send email without an SMTP server. Can someone describe the implications of sending email without an SMTP server? Dropped connections? No indication if message is undeliverable?
What are the implications of running my own SMTP server? Does it open up additional security holes? Can you recommend an open source SMTP server that requires minimal setup and maintenance?

Have a look at Haraka. It's an easy to use SMTP server that should do exactly what you're looking for. It's currently in use by Craigslist, so you know it's solid.
There's a section in the docs on how to set it up for sending mail - very last section 6.1.

Related

can we send mail without using the smpt port number host name

I am having username and password for a email account, but not smtp host name and port number,
I am using nodemailer.
Is it possible to send mail using only the username and password for the email account.
Edit: don't tell me to close, I have this doubt, If you know the answer tell me, this is not the silly thing, In my office they told me use only username and password. I searched online for it but did not got any idea.
You would always need smtp server details all the time along with username and password. And completely depends on smtp server how it handles the smtp details.
Few examples of smtp servers -
smtp.gmail.com
smtp.sendgrid.com
smtp.zoho.com
smtp.dreamhost.com
NodeMailer provides support for transports other than SMTP. You can check the link https://nodemailer.com/transports/. Looking in the documentation, it doesn't need SMTP server for these transports, you can give it a try.
In built support is there for below tansport.
sendmail – for piping messages to the sendmail command
SES – is a Nodemailer wrapper around aws-sdk to send mail using AWS SES
stream – is just for returning messages, most probably for testing

How to set up SMTP server in NATIVE nodeJS -- no dependencies whatsoever

I've seen many blogs and stack overflow questions about setting up nodejs to use a pre-existing smtp server, especially through modules like nodemailer etc. Some of what I've already seen:
https://www.zeolearn.com/magazine/sending-and-receiving-emails-using-nodejs
Use smtp client to send email without providing password
How can I create a custom smtp server to send out notification emails in Nodejs?
Sending emails in Node.js? (DON'T KNOW WHY IT IS CLOSED)
Use smtp client to send email without providing password
Nodemailer with Gmail and NodeJS
Nodemailer send email without smtp transport -- this is a tiny bit closer to what I want
How can I create a custom smtp server to send out notification emails in Nodejs? -- this one is so close yet no answers
Sending email via Node.js using nodemailer is not working
SmtpJs API not working! is there any way to send emails using SMTP server with JavaScript or JQuery
Email NodeJS cannot send
Any suggestion for smtp mail server in nodejs? -- this one may be the only one that even attempts to answer it, although from the docs for the service mentioned there (smtp-server), I don't see where the actual makings of the SMTP server from scratch are, i.e. I don't see the part that shows how to make your own myemail#mydomain.com using nodeJS (assuming the NodeJS server is configured on some kind of linux VM like google compete engine).
All of these answers and blogs only addressed sending emails via some other email client.
I am not interested in any other email servers.
I don't believe in gmail -- or any other 3rd party email providers.
I want to host my own.
From my own computer.
Don't question my intentions.
It's a perfectly valid programming question:
How do I create, from absolute scratch (i.e., only using the "net" built-in library in nodeJS, no external dependencies at all) create a SMTP mail server (assuming I have my own domain registered at an HTTPS virtual machine somewhere), that has the ability to receive mails at myemail#mydomain.com, and send emails from myemail#mydomain.com, without any 3rd party servers at all.
How can I at least start to do this? Any possible reference or tutorial that deals with the SMTP socket protocols would be a great start.
Some friendly advice -- you probably want to use an off-the-shelf MTA like postfix, exim4, or sendmail if you just want to receive mail on your local machine.
I say this because I have literally spent a good hunk of my career implementing MTAs and feel I should warn you that this is a solved problem that allows you to have complete control over your mail traffic, and there are some very tricky issues to solve to write an MTA that works at scale with large mail volumes.
That said, SMTP (note spelling) is a very simple protocol, and a great "first protocol" to implement if you're interested in that stuff. It would be very easy to write one in NodeJS.
The first edition you'd be interested in was released some time around 1982, as RFC-821, aka IETF STD-10. It was then updated over the years to RFC-2821 and a bunch of related specs, but basic RFC-821 support will get you what you need to talk to 99% of hosts on the Internet today. (That number will go down as you need ESMTP support for TLS - but this is not much harder nor much different).
Your daemon will need to listen on port 25, and need to process commands like this:
YOU: 220 my.computer.com SMTP Service Ready
THEM: EHLO blah blah
YOU: 500 Syntax Error. Try again using SMTP.
THEM: HELO blah blah
YOU: 250 G'day mate
THEM: MAIL FROM: <billg#microsoft.com>
YOU: 250 Sender Okay
THEM: RCPT TO: <steve#apple.com>
YOU: 250 OK
THEM: DATA
YOU: 354 Enter mail, end with "." on a line by itself...
THEM: <BUNCH OF STUFF>
.
YOU: 250 Mail accepted
THEM: QUIT
YOU: 221 Goodbye
Obviously there is more here wrt error handling etc -- read the spec -- but this is the gist of it. The numbers are response codes and have specific meanings. The lines are separated by \r\n and are supposed to be less than 1024 bytes wide.
<BUNCH OF STUFF> is an email message, and will not have a line which is just a dot in it. If the email had a dot like that, the other end will send an extra dot. This is in the spec.
Finally, write <XXXX><BUNCH OF STUFF> into your $MAIL file (probably /var/mail/username or /var/spool/mail/username) and point your MUA at it. Pine, Alpine, Elm, or mutt would make a good MUA for sorting this stuff out.
<XXXX> needs to start with From (NO colon) and end with \n. This is the Berkeley mbox file format. It should reflect the MAIL FROM header in the SMTP transaction.
This file format is very common and supported by most POP3 and IMAP4 servers. You can probably also read it with Mozilla Thunderbird. I know Netscape Mail supported it back in the day.

Do I need SMTP or POP3 on the server to run PHPMailer?

I have a busy CentOS webserver that sends a lot of outbound email using PHPMailer. Postfix and Sendmail are both installed on it, but as there are no user accounts that use the server for email, I wonder if I can uninstall both of those and close ports 25,110,465,587 for security. Will PHPMailer still be able to send outgoing?
No, PHPMailer (and any other mail library for any programming language, for that matter) is just an interface for the email service and not a mailer daemon by itself.
You do not need POP (you can shut that down anytime) but you will need sendmail or some other SMTP service to actually do the work PHP Mailer requests.
If you definitely need to shut down sendmail and the related ports, you can always part ways with it and implement your mail delivery logic using Mailgun, SendGrid, Elastic Email, Pepipost or some other alternative. There WILL be coding involved as you'll need to interact with those providers' APIs and they all involve some costs (Mailgun and Sendgrid have free tiers for a couple thousand emails per month, I don't remember if the others do as well) and integration efforts.
I believe you should be fine to remove any local mail service as PHPMailer is made to use an external service. You can close those ports as it's only outgoing!
The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.
https://github.com/PHPMailer/PHPMailer
Indeed you do not need to have a local mail server, however, if it's really busy, sending via a local mail server will be far more efficient than sending via any external service, especially if these messages are being sent immediately (and synchronously) in response to HTTP requests. You can see more about this in the PHPMailer wiki on github.
You definitely don't need POP3, but you may need inbound on port 25 if you're going to receive/handle bounces from the messages you send and want them to come back to you.
In this scenario you would only need port 25 open in both directions, none of the others.
Also, be clear what you mean by sendmail. Postfix is a complete mail server and so is sendmail, but the name sendmail is also often used to refer the sendmail binary that is actually a local message submission agent - it's what gets used by the PHP mail() function. postfix provides a sendmail binary, but postfix is not sendmail.

Implement mail confirmation without using external mail server?

I'm building a Hapi app and I want to implement basic user email confirmation feature. I'm a bit lost as I don't have prior experience on mail servers nor have I implemented mailing feature to any apps. I do NOT want to use external mail service such as Google for sending the emails. There is also no need to be able to receive email nor store the sent messages. I want the emails be sent from address 'mailerbot#mydomain.com', where I already have a running web app in mydomain.com. The server is a Centos 7 running in EC2.
Do I have to setup own mail server (Haraka, Postfix, etc.) or can I send email directly to the users from my Node.js app (Nodemailer, Hapi Mailer, etc.), without using neither local nor remote mail server? I looked at some examples, but they usually use Google or such for sending the mail, so I'm not sure how to achieve exactly what I want, i.e. simple mail confirmation messages sent from Node.js app.
Node.js does not have a built-in SMTP server, and you must have an SMTP server of some kind to send email.
It is possible to run your own SMTP server with Node.js (https://github.com/andris9/smtp-server) and then use Nodemailer or Hapi Mailer with it.
Try using this : https://github.com/paullang/hapi-mail
This is a plugin built especially for hapi.

Sending e-mail from computer on network - .NET 4.0

I am trying to create a small desktop app that sends out e-mails to people in the office (all internal). My application would run on a PC that is also on the network and the user will have outlook running for his own e-mails.
I'm looking at several examples where you need the SmtpClient and it needs to equal a host. Is there a way that I can just set it to use the local machine?
MailMessage mailObj = new MailMessage("admin#network.com",
reader["recipientAddress"].ToString(), "Subject", "Body");
SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
SMTPServer.Send(mailObj);
I read that 127.0.0.1 is the local machine. Would this work, or is there a different way of going about this?
Also would my messages go out if it sent a message to an external email?
You have to install a SMTP server on your localhost to be able to send mail.
Outlook only receives e-mails through POP3 or IMAP, etc.
edit:
i.e. you need
some server that accepts mail through SMTP from your client and forwards it to its destination; and
some server that accepts mail (normally through SMTP) and stores it in a mailbox, so people can retrieve them later through POP3 or IMAP or whatever means.
Your company mail server should normally do both.
edit2:
You might be able to cheat and use SMTPClient to deliver the mail to the receiver's mailbox server directly though.
Try resolving for the MX record (see How to get mx records for a dns name with System.Net.DNS?) and create a SMTPClient directly to the best MX server returned.
If Microsoft implemented enough of the SMTP specification and your host is not treated as sending spam, the mail should go through.

Resources