Command-line SMTP Server?

1

Is there a free command-line-based, lightweight SMTP server for Windows?

All I'm looking for is the ability to send HTML emails from the command-line, using a standalone EXE, with the program being its own server (rather than using some other server like Gmail).

By "lightweight" I mean there should be a single executable, or -- if not possible -- it should come with at most a handful of supporting DLLs, and run standalone (i.e. without installing anything).

Specifically:

  • I am not looking for hMailServer. It may be awesome, but it's still bloated for sending a single email. I just need a command-line tool I can have handy on a flash drive or a recovery environment -- something that does not require installation.

  • The server needs to support TLS -- i.e., it should be able to send mail to major providers like Gmail, which require encryption.

  • IIS fails every test: it's (1) not lightweight and (2) not standalone.


For those who claim Gmail doesn't need encryption:

$ telnet smtp.gmail.com 25
Trying 209.85.225.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP a9sm264065ibi.26
HELO
250 mx.google.com at your service
MAIL FROM: my_email@gmail.com
530 5.7.0 Must issue a STARTTLS command first. a9sm264065ibi.26

What am I doing wrong?

user541686

Posted 2011-08-17T04:04:12.097

Reputation: 21 330

@Mehrdad Is it actually a server? did you check? – barlop – 2014-09-15T16:59:05.623

@RandolfRichardson You soudn familiar with Blat. The question asked for an SMTP Server. Is this actually a server? – barlop – 2014-09-15T17:00:06.667

GMail doesn't require TLS or any type of encryption for SMTP. (I just confirmed this by making a raw connection with PuTTY on TCP port 25 and manually sent a message to myself without only four commands, none of which involved any encryption.) – Randolf Richardson – 2011-08-17T04:32:17.603

@Randolf: What were the commands? Each time I tried, it told me I have to use TLS... – user541686 – 2011-08-17T04:38:58.543

Standard SMTP commands -- HELO, MAIL FROM, RCPT TO, DATA (QUIT is outside of that because a successful return code following a properly completed DATA command is all that's required to send a message; using QUIT to end the session is still important though). – Randolf Richardson – 2011-08-17T04:50:41.503

Regarding "the program being its own server," what you're looking for is what's called a "direct-to-MX mailer" that performs its own lookups for MX records (so that you don't have to specify an SMTP server). If you don't need something that will queue your message and retry later on, then a command-line tool can work quite well for that. Otherwise, I suggest David Harris' wonderful Mercury/32 mail server (doesn't use the Registry -- it's a text file configuration only) in which you can simply create a text file in the queue: http://www.pmail.com/overviews/ovw_mercury.htm

– Randolf Richardson – 2011-08-17T04:57:28.763

@Randolph: How come I'm getting that error message regarding TLS? Am I issuing the wrong commands or something? And thanks for the link, I'll take a look at that! – user541686 – 2011-08-17T05:12:40.017

Try adding your hostname as a parameter to the HELO command (I believe a hostname is required, although there are many SMTP servers that don't comply with standards). – Randolf Richardson – 2011-08-17T05:21:46.913

@Randolph: I tried; it made no difference. – user541686 – 2011-08-17T06:04:02.320

You have a space after the colon for the MAIL FROM command (I didn't notice this earlier), but spaces aren't permitted in eMail addresses (unless properly quoted). You also need to enclose your eMail addresses within angle brackets. This all applies to the MAIL FROM and RCPT TO commands. See section 3.3 on page 19 of RFC 5321 (Simple Mail Transfer Protocol): http://rfc5321.openrfc.org/

– Randolf Richardson – 2011-08-17T06:08:39.583

Also, you should be using the SMTP server that is defined in the MX record in the "gmail.com" DNS zone. The one with the highest priority (5) is: gmail-smtp-in.l.google.com – Randolf Richardson – 2011-08-17T06:14:59.340

1@Randolph: :O OMG, it worked! So it was an issue with the server... interesting, thanks a lot for the info. But how do you figure out which server you need to connect to, when all you have is the email address the user gives you? Is there a way to look it up with DNS or something? Thanks! – user541686 – 2011-08-17T06:25:09.993

You have to look it up for every site. In the DNS zone there are usually MX records (if not, then just use the domain name itself, but this is always a last resort as MX records are always preferred). With each MX record will be a Priority and a Hostname (IP addresses are not allowed, and many SMTP servers will fail to deliver if an IP address is specified in an MX record); always choose the higher priorities (lower values) first. – Randolf Richardson – 2011-08-17T06:29:34.807

1@Randolph: Interesting, thanks a lot for the info; that's really helpful! (BTW, my emails went to spam, lol...) – user541686 – 2011-08-17T06:50:13.040

Answers

2

I use Blat to send mails from the command line and have also used this in programs to send mail as well. It is a single executable.

enter image description here

Daniel Williams

Posted 2011-08-17T04:04:12.097

Reputation: 1 276

Is this a server? "What is Blat (and what does it do)?

http://www.blat.net/?faq/index.html#what_is_blat_(and_what_does_it_do) "What is Blat (and what does it do)? Blat is a small, efficent SMTP command line mailer for Windows. It is the SMTP sending part of an eMail User Agent (MUA) or eMail client. As such, Blat sends eMail via SMTP (or internet eMail) from the command line, or CGI, ..." <-- looks like not a server.

– barlop – 2014-09-15T16:56:49.467

And regarding the -install option. from the same page http://www.blat.net/?faq/index.html#cl__why_should_i_run_blat_install... "CL - Why should I run Blat -install...?

Because it simplifies the command line by storing any or all of the following in the registry SMTP Server Address Sender's Address " <-- So looks like that option doesn't make it a server.

– barlop – 2014-09-15T16:57:35.920

I just tried it with blat Email.txt -to my_email@gmail.com -server smtp.gmail.com -f my_email and I got Blat v2.6.2 w/GSS encryption (build : Feb 25 2007 12:06:19)

Sending Email.txt to my_email@gmail.com Login name is my_email The SMTP server does not like the sender name. Have you set your mail address correctly? – user541686 – 2011-08-17T04:43:45.837

Right, gmail needs SSL. For this I use another light program called stunnel http://www.stunnel.org/ You set up stunnel to run on a local port, say 2099, and then tell blat to send to 127.0.0.1:2099 Not pretty, but still lightweight and it works. I even used this stunnel trick to get Sharepoint to send to gmail accounts. Good luck!

– Daniel Williams – 2011-08-17T04:50:26.750

The only problem with "blat" is that it doesn't perform its own DNS lookups for MX records -- you have to specify the server. +1 because this is a good solution otherwise though (and there are dozens of alternatives, all of which don't seem to perform their own MX record lookups). – Randolf Richardson – 2011-08-17T04:52:22.610