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.
Related
I have a VPS server with CPanel on my domain (say mydomain.com). I have a SuiteCRM installed on a subdomain (say sub.mydomain.com) and I am sending mass emails from it in a batch of 90 every hour.
While sending the emails from the CRM (Authenticated SMTP mode) the emails are getting deferred with the error:
SMTP error from remote mail server after MAIL FROM:< myemail#mydomain.com> SIZE=562346: 451 <myemail#mydomain.com> server temporarily unavailable. AUP#MXRT
The SPF, DKIM and DMARC everything is fine.
I am suspecting it could be a max rate warning/failure (MaXRaTe hence MXRT) from the remote/recepient mail server. It is failing/deferring emails for Gmail, Yahoo and other email providers not for any company-specific emails like someone#somecompany.com
There seems a limit on emails for Gmail and other vendors. I had gone through these where Gmail specifically pointing out the limits and do's and don'ts:
https://support.google.com/mail/answer/22839?hl=en#zippy=%2Cyou-have-reached-a-limit-for-sending-mail
https://support.google.com/mail/answer/81126
In my case, I find myself well under the limit. So, why I am getting this error?
Second thought: It could be due to that I am sending 90 emails in one go. If I send emails one-by-one after a delay (say 3-5 seconds) then there won't be any problem. Enlighten me on this too.
I later realized that, even any one-to-one email I am sending via Thunderbird from my server (SMTP), even to a single recepients, is failing. I have checked check.spamhaus.org and intodns.com everything is alright there.
My Environment (Though this hardly matter in context of my problem but just in case):
BigRock's VPS Server with CPanel (Version)
Apache Version: 2.4.53
MySQL Version: 8.0.29
WHM Version: 102.0.18
CentOS Version: 7.9.2009 (Standard KVM)
Note: I haven't mentioned my actual domain name just for the privacy and security since I feel putting everything here will pose risks.
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.
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.
I have an IIS7 web server at Rackspace that is being utilized/attacked in some manner to send SPAM. I have run several variations of anti-virus and malware software on the server and cleaned anything found, but it is still happening.
I'm leaning towards some kind of web form attack, but there are several sites on this server and I didn't create all of them, so figuring out what form(s) is being used (or even where they all are) is proving challenging.
Does anyone know of any solution to pinpoint what script(s) might be firing off these emails? Is there any way to monitor the SMTP service with more information? I've looked at SMTP logs, but all I see are things like:
2014-02-14 06:00:52 127.0.0.1 [---server info, etc---] SMTPSVC1 [-compname-] 127.0.0.1 0 MAIL - +FROM:<--------#-------------------> 250 0 56 43 0 SMTP - - - -
In fact, there are 19,608 in about a 16 hour period in this one log file I'm looking at. But unfortunately, this doesn't seem helpful.
If anyone could offer any insight, that'd be great!
If I had to guess, you have a webpage that has been compromised (which is what I think you suspect), and is being used to generate all the messages. The webpage probably accepts a FROM and a TO, without any validation.
If you start seeing these come in, as a test, start shutting off websites, until you see the attack stop.
Then, start the website back up, see if it continues. Then, I would start grepping that website location for files relating to email.
Most likely your server is configured to act as an email relay server, which allows anyone to send email that is in transit to your server for your server to send on (relay). Spammers do this to cover up the original origination point of the email.
The fix is to configure your server not to be a relay server. More background info here:
http://en.wikipedia.org/wiki/Open_mail_relay
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.