Not only is email very useful for communication between friends and families and sending messages with attachments such as reports, photos, documents, presentations, video clips and music files, it’s also useful for notification purposes. For example, a website monitoring service such as Pingdom has alerts where you’ll be notified through different methods such as email, SMS, twitter or in-app when your server is down. Third party backup software also normally has at least an email notification feature where you can set it up to automatically email you when the backup process has completed or failed.
If you are writing a batch file and want to send an automated email when the batch has completed running or if you’re faced with a third party software that does not even support email notification, then the simple solution is to use a command line email sending tool for Windows. Here we have 7 ways to look at.
An example command line for sending an email using Gmail is given for every utility mentioned below. You’ll need to change the following information in the command line option:
- sender@gmail.com = Replace it with your full Gmail address
- recipient@email.com = Replace it with the email address that will receive the message
- YourGmailPassword = Replace it with your Gmail password
- subject = The subject of the email. Make sure it is enclosed with double quotes if there are spaces. For example, “This is a long subject“
- body = The message of the email. Should also enclose with double quotes if there are spaces
1. SwithMail
Out of all the command line email sending tools, we’d consider SwithMail as one of the best in its class, if not the best. Instead of the need to write really long command line options to silently send an email where you might make mistakes and need a few tries to get it right, configuring SwithMail is quite foolproof thanks to the easy to use settings configuration GUI. You even test the email settings to make sure that it is able to successfully send an email.
Other than the standard options such as attachments, CC, BCC that you’d normally find when sending an email, SwithMail supports returning error codes, global variables and wildcard attachments which is very useful to automatically send log files with dated filenames. Below is a working example of SwithMail command line options to send an email using Gmail account.
SwithMail.exe /s /from sender@gmail.com /pass YourGmailPassword /server smtp.gmail.com /p 587 /SSL /to recipient@email.com /sub subject /b message
Download SwithMail
2. CMail
If you need to use a command line email sending tool that supports proxy, CMail would be your choice as it’s the only one that can support socks and HTTPS based proxy. Other interesting features that can be found in CMail are sending the whole directory content based on wildcard attachment and delivery status notification.
The full working command line to send an email using Gmail is as follows:
CMail.exe -secureport -host:sender@gmail.com:YourGmailPassword@smtp.gmail.com:465 -from:sender@gmail.com -to:recipient@email.com -subject:subject -body:message
Download CMail
3. SendSMTP
Running SendSMTP will bring up an interactive graphical user interface to send emails but at the same time it also supports command line instructions to silently send email with just one line of commands. Although an advanced user would have no problems with the command line arguments, a GUI will greatly help a basic computer user in creating a working config file.
Some notable features found in SendSMTP are the ability to save the password as encrypted using 128-bit Rijndael (AES) rather than saving the password as clear text, enable log file to save the activity of the SendSMTP program, and can return codes to report if the send email is successful (0), failed (1), or cannot find settings (2). The full command line for SendSMTP to send email using Gmail is as follow.
SendSMTP.exe /nos /host smtp.gmail.com /port 587 /auth 2 /userid sender@gmail.com /pass YourGmailPassword /from sender@gmail.com /to recipient@email.com /subject subject /body message
However, if you’ve saved the settings as default from the GUI which will create a SendSMTP.ini file at the same location as the program, a much shorter command line can be used to send an email.
SendSMTP /s SendSMTP.ini
Do note that there are 2 versions available on the download page. You will need the newer version with the bigger file size to support sending email using Gmail because the old version does not support SASL authentication.
Download SendSMTP
4. mailsend
Comparing with the utilities mentioned above, mailsend is a simpler command line tool to send email using SMTP. It doesn’t have fancy features such as loading config from an external file, password encryption, GUI, error codes and etc. However, an interesting feature found in mailsend that is not available on other command line email sending tool is the ability to show SMTP server information by using the -info option.
mailsend is available for both Windows and Linux operating system. Below is the example command line for mailsend to send an email using Gmail.
mailsend1.17b15.exe -t recipient@email.com -f sender@gmail.com -ssl -port 465 -auth -smtp smtp.gmail.com -sub subject -M message -user sender@gmail.com -pass YourGmailPassword
Download mailsend
5. Send-It-Quiet
Send-It-Quiet is the smallest command line SMTP mailer utility that weighs only 14KB in size and this is made possible with .NET Framework. This would also mean that you need to have .NET Framework 3.5 installed to run Send-It-Quiet. Send-It-Quiet only comes with very basic parameters that are enough to send an email. Possibly the only extra features found in Send-It-Quiet are the return value of ERRORLEVEL and also the flexibility of manually adding the parameters to registry.
The command line to send an email using Send-It-Quite with a Gmail account is:
senditquiet.exe -s smtp.gmail.com -port 587 -u sender@gmail.com -protocol ssl -p YourGmailPassword -f sender@gmail.com -t recipient@email.com -subject subject -body message
Download Send-It-Quiet
6. SendEmail
SendEmail is written in Perl but there is no need to install Perl in Windows for this command line mailer utility to work. SendEmail was last updated in 2009, but the last version has TLS support which means it can send email using Gmail SMTP. In terms of features, it is quite similar to Send-It-Quiet which only supports the standard email sending options such as to, from, subject, body, attachment, etc. SendEmail is available for both Windows and Linux operating systems.
Here is an example of the command line options that can send email using Gmail SMTP.
sendEmail.exe -o tls=yes -f sender@gmail.com -t recipient@email.com -s smtp.gmail.com:587 -xu sender@gmail.com -xp YourGmailPassword -u subject -m message
Download SendEmail
7. PowerShell
PowerShell is included in Windows operating systems since Windows 7 which means you can actually use a powershell script to send an email through Gmail SMTP without any of the command line tools mentioned above.
The sample script that can be downloaded at the link below is a very basic one that is meant to only send an email without attachment support. Simply download the ps1 script, open it with Notepad or Windows PowerShell ISE and change the credentials located at line number 8. The command line to run the powershell script is as follows. Make sure you update the path to the .ps1 file.
Powershell.exe -executionpolicy remotesigned -File C:UsersRaymondsendemail.ps1
Download PowerShell Script to SendEmail
The popular Blat is not included in the list because it does not support SSL which means it cannot send email using Gmail SMTP. Bmail (last updated in 2004), cmdsendmail which is a part of CommandLine Tools, and XmlSendmail are also example of command line send mail utility that doesn’t support SSL.
Can anyone help me out, we need to send mail through command line from Window server. We cannot use Blat as per security issue and neither do we want to install Exchange resource kit. We have our own Mail exchange server we can make use of it.
May be if any batch which could be run to access our SMTP mail server.
Thanks in advance.
asked Mar 1, 2011 at 11:38
Ravi VanapalliRavi Vanapalli
9,7073 gold badges31 silver badges42 bronze badges
1
Assuming you don’t want to install any SMTP client whatsoever, and just want to use windows and perhaps batch files, you could use Telnet to connect to port 25 of your smtp server and send the commands manually.
Here is an example of how to do this.
Anyway, I personally would prefer to install some command line SMTP client such as Blat or Bmail, instead of going into the hassle of directly interacting with SMTP.
answered Mar 1, 2011 at 12:09
a very nice solution I found generically good if no authentication is involved and no programs can/should be installed or can be assumed to exist is the following, which should work on Ubuntu and other Linux platforms alike (you can put everything in one line using the ;
command delimiter and removing the chars in the
echo
quoted string):
set sender="<sender@example.com>"
set recipient="<recipient@example.com>"
set subj="testsubj"
set body="testbody"
set srv="mysmtpsrv.com"
set port="25"
set crlf="x0Dx0A"
echo "EHLO man${crlf}
MAIL FROM: ${sender}${crlf}
RCPT TO: ${recipient}${crlf}
data${crlf}
Subject: ${subj}${crlf}${crlf}
${body}
${crlf}.${crlf}"
|
nc -Ci 1 ${srv} ${port}
(Using like this make sure you are saving the file in Unix style (only a x0A
character will be added after the echo "...
backslashes).
Otherwise just remove the backslashes and the newline which puts everything on a line and makes it work, but less visually structured.)
answered Dec 13, 2013 at 21:50
Andreas CovidiotAndreas Covidiot
4,1385 gold badges48 silver badges95 bronze badges
HowToGeek demonstrates a Windows PowerShell script that works very well at How To Send Email From the Command Line in Windows Without Extra Software
Here is the method:
First you’re defining the variables:
$EmailFrom = “yourMail@gmail.com”
$EmailTo = “theRecipient’sAddress@someServer.com”
$Subject = “your subject”
$Body = “some text”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“yourGmailUsername”, “password”);
Then, you’re using this command to send the mail:
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
You’ll need a valid Gmail account in order to authenticate as a Gmail user.
answered Dec 7, 2014 at 5:18
Oz EdriOz Edri
5515 silver badges8 bronze badges
To send mail from command line in windows:-
Save this in a text file and name that file something like sendmail.ps1
$EmailFrom = "from@gmail.com"
$EmailTo = "to@domain.com"
$Subject = "The subject of your email"
$Body = "What do you want your email to say"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("gmail_username", "password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
-Don’t forget to put the valid email address and password.
Now open CMD and write this command
Powershell -ExecutionPolicy ByPass -File C:sendmail.ps1
Voila! mail sent!!
answered Nov 27, 2015 at 11:05
GorvGoylGorvGoyl
38.5k26 gold badges213 silver badges203 bronze badges
This is an example to send mail from your Gmail address, for other servers you need to change the -smtp and -port
$securepass = ConvertTo-SecureString -String $yourpassword -A -F
$credential=new-object PSCredential $yourusername,$securepass
send-mailmessage -from «$yourusername@gmail.com» -to $recipient -subject «subject» -body «message» -smtpserver smtp.gmail.com -port 587 -usessl -credential $credential -encoding utf8
Here is the script that can send mail from your Gmail:
https://gallery.technet.microsoft.com/scriptcenter/PC-Utilities-Downloader-355e5bfe
answered Mar 20, 2016 at 7:25
k8Ck8C
4144 silver badges9 bronze badges
0
SendItQuiet is a software for Windows that lets you send email from command line. It can also let you attach files and supports SSL connection. This software can be best to use for sending bulk emails from command line via a batch file. This software is capable of sending files as an attachment and supports sending emails to multiple recipients which can be supplied to the software as a parameter.
You would not require any kind of technical knowledge to use this tool to send email from command line. This software runs without any installation and can be used directly from the folder it is downloaded to. Read on to find out how to use this software.
Now, if you thought that it would be too difficult for you to understand this software then let me tell you that it is very easy to use this software.
Hope you know how to open up the command prompt but just so if you don’t know, press Windows Key (Key with Windows Logo) + R. The “Run” box will pop up. Once we get the Run Box, type in “cmd” and click on “OK”. There we go. We would have the command prompt.
SendItQuiet does not have a graphical interface. This means that we don’t have buttons and menus to click on and to choose from. It does not have text boxes where you can type in the email address. You might ask “How would we work with it?”. You would use the command prompt (Black Screen that we just pulled up) to provide the required information to the software. To invoke the software, we simply type the name of the software. Then we follow that with a few additional parameters that specify email address, server address, actual message, etc.
Ex: senditquiet -s smtp.gmail.com
Here, -s is used to specify that we’re going to provide the server’s address and “smtp.gmail.com” is the actual information we pass on to the software.
Different Parameters to Use with SendItQuiet:
SMTP (Simple Mail Transfer Protocol) server
The SMTP server is the server where we are going to connect to and the switch we use to specify this is “-s”. Example: –s smtp.gmail.com. We have used Google’s SMTP server here for testing purposes. You can easily get the SMTP information from your Email provider on their website.
Protocol
Protocol is the way we connect with the server. We are going to use SSL (Secure Socket Layer), that means the information going out of the computer will be encrypted. Gmail uses this every time you want to send an email to someone. This is usually taken care of and happens in the background while your email client talks to the server.
We will specify it like this: “–protocol ssl”
Username and Password
Of course we would need the username and password to send the information to the Google’s SMTP and get our account verified. This is simple.
Specify –u for username, followed with actual usernam and –p for password., followed by actual password. Example: –u yourusername –p password
From and To Address
You need to type in the From Address that would show up on the receiver’s end. You would also need the receiver’s email address so that goes into the To Address.
Parameters for this: –t for To address and –f for from address.
Example: –f myemailaddress@gmail.com –t receiveremailaddress@yahoo.com
To send to multiple address: –t address1@gmail.com; address2@gmail.com; address3@yahoo.com
Subject and Body
What should go in there? Well, whatever you wish to put in there. You can specify the body and the subject with the “-subject” and “-body” parameters. Example: –subject “Test Mail” –body “This is a test mail from Ilovefreesoftware.com”
Ports
You would require to specify the port number in case if you’re Email service provider needs them desperately. For, Gmail the port is taken care by the software we are going to use. However, you should specify the port according to the specifications of the Email Service Provider.
Files
An email client without a feature to send files as an attachment would be absolutely incomplete. This software would let you do that. The parameter for this is: –files. Example: –files file1.txt, document.pdf, document.xls
To send an email from command line, the complete command would look like this:
senditquiet -s smtp.gmail.com -protocol ssl -u myusername -p password -f myemail@gmail.com -t recipientsemail@yahoo.com -subject "Test Mail" -body "This is a test mail." -files file1.doc
This is how it would look for real. I have used my Gmail account here. You can see the file – file1.txt sent with our software to send email from command line.
How to use this software in a batch file?
To create a batch file, open up the Window’s Notepad or any of you’re favorite text editor. Once we’re in there, type in the command we want to go in there, one command per line. We can use SendItQuiet with more than one recipient and parameters with one command per line. Here is how we do it.
We got for far, now it’s just the “File Saving” part left. We have to save this file as a .bat file. We choose the Save option from the File Menu and type in the name of the file and add .bat next to that as an extension. Now in the file type, we would choose All Files.
Conclusion
SendItQuiet quickly lets you send email from command line. Because, it can also send files as an attachment, it can be used while sending bulk emails. It can completely automate the task of manual login and process of authentication. You can schedule emails and set it for a specific time to be sent out. It could be an hourly update of a file that you want to send as an email. The possibilities are many and this is just the beginning. I liked this tool and hope you’ll find it useful too.
Get SendItQuiet here for free
28 Replies
-
-
You can modify this how-to and make it work for you — assuming you are going to be repeating this process.
http://community.spiceworks.com/how_to/show/382-how-to-automatically-email-reports
Was this post helpful?
thumb_up
thumb_down
-
-
Being an old fart, I used telnet from the command line for e-mail testing, assuming the appropriate ports are open. from the DOS box (Command Prompt for the young ‘uns) it’s;
1. Telnet mail.domain.com 25 (obviously replace mail.domain.com with whichever mail server you want to use.)
2. helo your domain name
3. mail from:your email address
4. rctp to:destination address
5. data
6. Type your message
7. . (type a period and hit enter)
At that point, your email message should be queued and sent. To make it a little clearer, here’s an example sending from fred.com to barney.com. Hit «enter after each line.
1. telnet mail.barney.com 25
2. helo fred.com
3. mail from:fred@fred.com
4. rcpt to:brubble@barney.com
5. data Hello Barney. Bowling tonight?
6. .
Hope that makes sense.
Was this post helpful?
thumb_up
thumb_down
-
You can always use the old standby telnet (you’ll probably need to enable telnet in windows features (control panel>>>programs>>>turn windows features on or off, then check the box next to telnet client):
This is a good «how to» using an smtp server:
http:/ Opens a new window/www.wikihow.com/Send-Email-Using-Telnet Opens a new window
-Rob
Was this post helpful?
thumb_up
thumb_down
-
+1 Shane
Old school or not, I’ve used this more then once to troubleshoot mail servers.
Was this post helpful?
thumb_up
thumb_down
-
Blat.
IMHO, the absolute best command-line mailer for the windows platform. hands down.
It’s supposed to (I think) support mapi, but I’ve always stuck with SMTP. If you don’t have a mail server to point to, you can always install the Windows SMTP service (in there with IIS) and configure it to only accept/relay mail for 127.0.0.1
and it has more logging/debugging options than you’ll likely ever need.
Was this post helpful?
thumb_up
thumb_down
-
I always use «telent <host> 25» like some of the other folks here for troubleshooting.
Just a side note about telnet and Windows7, in case you weren’t aware, it’s not installed by default. You have to go into Programs and Features and enable it via the «Turn Windows features on or off» dialog.
Was this post helpful?
thumb_up
thumb_down
-
http://www.smtpinfo.com/ Opens a new window — the free version should serve most purposes
Was this post helpful?
thumb_up
thumb_down
-
I also use Blat, mainly for emailing log files and results of batch scripts. Does the job nicely.
Was this post helpful?
thumb_up
thumb_down
-
+1 for telnet, as described by Shane,
best way to troubleshoot, got to be very careful with your typing, as you cannot backspace out errors, but very useful info returned to spot if something isn’t getting through
Was this post helpful?
thumb_up
thumb_down
-
Powershell with one line
send-mailmessage -from «fromname <me@address.com>» -to «toname <me@address.com>» -subject «Subject» -smtp <mailserver> -body «body»
Was this post helpful?
thumb_up
thumb_down
-
OJB
This person is a verified professional.
Verify your account
to enable IT peers to see that you are a professional.serrano
+1 Shane
You didn’t mention if you have a local mail server or hosting service. Your ISP may block port 25. If it’s a home pc port 25 is blocked by your ISP.
Was this post helpful?
thumb_up
thumb_down
-
i use blat only because it was what i learned first, but really do like it and have gotten very comfortable scripting messages and setting them up as scheduled tasks.
Still think that repeating a message to oneself in scheduled tasks every minute would make a great practical joke.
Was this post helpful?
thumb_up
thumb_down
-
I’ve used Blat in the past, but on Windows boxes this is what I mostly use now. Save as a PS1 file and modify it to suit your environment.
# Send mail through Gmail account
$EmailFrom = «notifications@somedomain.com»
$EmailTo = «me@mydomain.com»
$Subject = «Notification from Whomever»
$Body = «this is a notification from Whatever Notifications..»
$SMTPServer = «smtp.gmail.com»
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(«username», «password»);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Was this post helpful?
thumb_up
thumb_down
-
Here’s another option. It’s called SendEmail. No install required. Handles authentication, if needed.
http:/ Opens a new window/caspian.dotconf.net/menu/Software/SendEmail Opens a new window
I use this to send e-mail through a scheduled task to confirm execution.
Was this post helpful?
thumb_up
thumb_down
-
If moving to a new system or ISP with blat, make sure you are not trying to send pop3 smtp through an ssl account , unconfigured port, or ISP unsupported port.
Even in debug mode, blat will grind to a halt with no diagnostics, only a generic windows error:
«A Win32 command line eMail tool has stopped working»
Was this post helpful?
thumb_up
thumb_down
-
to enable telnet from cmd
sc config tlntsvr start= auto
Was this post helpful?
thumb_up
thumb_down
-
If you already have powershell installed, you can just call up the SmtpClient from System.Net and it’ll send whatever email you want. There’s a guide that explains sending email via the windows command line Opens a new window using powershell you can check out.
Was this post helpful?
thumb_up
thumb_down
-
This WORKS REALLY GREAT I spent hours to sent email from other clients with no luck ( not so good in emails:-) ). Here you got everything even with working examples. Thank you and have a nice day
Google MailSend. No need to mess with the Powershell. http://muquit.com/muquit/software/mailsend/mailsend.html Opens a new window
Was this post helpful?
thumb_up
thumb_down
-
Sendmail utility in Windows is working fine. But I am unable to attach a file.. Any reason..?
I have given the command -attach=filename (with full path)
Was this post helpful?
thumb_up
thumb_down
-
Hey am tried this way but getting erro msg regarding argument
Was this post helpful?
thumb_up
thumb_down
-
hari.p.rai wrote:
Hey am tried this way but getting erro msg regarding argument
Since there were multiple methods to do this presented in this thread you will need to provide more details.
Was this post helpful?
thumb_up
thumb_down
-
I tried following list of command:
$EmailFrom = «notifications@somedomain.com»
$EmailTo = «me@mydomain.com»
$Subject = «Notification from Whomever»
$Body = «this is a notification from Whatever Notifications..»
$SMTPServer = «smtp.gmail.com»
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(«username», «password»);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)through gmail i was to send but when i use my office id i am getting error regarding argument.
Was this post helpful?
thumb_up
thumb_down
-
hari.p.rai wrote:
I tried following list of command:
$EmailFrom = «notifications@somedomain.com»
$EmailTo = «me@mydomain.com»
$Subject = «Notification from Whomever»
$Body = «this is a notification from Whatever Notifications..»
$SMTPServer = «smtp.gmail.com»
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(«username», «password»);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)through gmail i was to send but when i use my office id i am getting error regarding argument.
you are using BLAT and it works when you send via google but not using your office exchange? Probably something wrong with 1 or more params with your office settings — or SMTP isn’t allowed from your terminal.
Was this post helpful?
thumb_up
thumb_down
-
Hi
There is a free utility called CommandLine Mail sender
Here Opens a new window
Was this post helpful?
thumb_up
thumb_down
-
Google reads, stores and shares your mail with NSA. You may say there’s nothing to hide, but if the rules change, they can go back to the archives — apparently they are keeping a lot of this stuff, including encrypted stuff with an eye toward eventually being able to brute force decryption.
Also you do not control the business policies of Google, its continuity,whether it is merged or acquired, nor whether and how it changes policies. If you embed it in systems and decide later you don’t want to use it, or are unable to continue using it, or must maintain something in order to continue using a modified API, you’re a bit out of luck.
Big, friendly, cool or not — I don’t entangle with other private parties without a contract and a proper business evaluation.
FWIW,
Greybeard who used Burroughs, IBM, Control Data, NCR, DEC, CompuServe, landlines, modems and a zillion other things that were likely to be part of the landscape forever. Yeah, right.
Was this post helpful?
thumb_up
thumb_down
-
There is a new and free command-line tool for sending emails called Mail Alert Simple Mailer:
https://sourceforge.net/projects/mail-alert/ Opens a new window Opens a new window
Mail Alert can send emails using SMTP servers with SSL/TLS, so it is working with gmail and other free email providers. It can save mail password in encrypted form, thus it is much safer then other solutions.
I’m using this software on Windows Server 2008 R2 to send hardware alerts from Dell OMSA and is very reliable.
Was this post helpful?
thumb_up
thumb_down
Read these next…
Merging two domains with the same name?
Windows
It seems that a possible company merger is coming down the pipeline, but as luck would have it, the active directory domains have the same name (ie, domain.local)The domain I maintain is running server 2019 at a 2016/2019 functional level.The other domain…
How can I track changes to network adapter configuration
Windows
Ok, so we have a site where most of the users have local admin and they have a small group of users who «know about computers». The site runs pretty smoothly but we’re seeing a bunch of users who are able to function on the wired network but aren’t able …
Snap! — Cooling in Antarctica, Back to the Moon, Biological Clothing, AI Sci-Fi
Spiceworks Originals
Your daily dose of tech news, in brief.
Welcome to the Snap!
Flashback: February 3, 1986: The term “vaporware” is first used by Philip Elmer-DeWitt in a TIME magazine article (Read more HERE.)
Bonus Flashback: February 3, 1966: Luna 9 Lan…
Safety Glasses with Glasses
Networking
I’m going to be pulling some new wire soon through some dirty drop ceilings, and without fail, at some point I always get a piece of something in my eye at some point during the job.I’d like to avoid that this time.I have struggled to find safety glasses …
AD on-premise courses
IT & Tech Careers
Hello!We have a predominantly on-prem AD environment. Whilst we will be moving to M365 that will be in a while.We have a number of junior staff that need basic instruction in Active Directory and file/folder permissions. I recall many years ago the MC…
[Leer este post en español]
If you want to send a mail from the command line you have to follow these simple steps, which are the same used by any ordinary mail client like Outlook. This means that you must send at least the following commands in the specified order:
- EHLO
- RCPT
- DATA
- QUIT
To begin the transmission of our mail using the command line we first open a CMD on Windows (Start -> Run and type “cmd” without quotes and press Enter). In Linux or UNIX you just have to open a terminal window with the root user or any other. Now, in the command line we start by writing the following line which will open a connection on port 25 of the mail server with which you want to transfer the mail.
telnet <mail_server_IP> 25
For example:
telnet 192.168.0.10 25
We’ll get a line similar to this one:
220 hub.rskala.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959
You don’t have to care about the text in this line, but the numerical code 220 which means the mail server is ready to start a mail transfer with us.
Now type the EHLO command to identify yourself with the mail server:
EHLO <FQDN>
For example:
EHLO server.domain.com
We’ll get a line similar to this:
250-hub.rskala.com Hello [192.168.0.89]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
Now we’re ready to start our mail transfer, so let’s begin by sending the MAIL FROM command which indicates what the sender’s mailbox is:
MAIL FROM:<sender_mailbox>
For example:
MAIL FROM:<john_doe@domain.com>
We’ll get a line similar to this:
250 2.1.0 john_doe@domain.com….Sender OK
Now we must indicate what the recipient mailboxes are, each on a single line. For this, we’ll send the RCPT TO command, one for each of the recipient mailboxes of our mail:
RCPT TO:<recipient1_mailbox>
RCPT TO:<recipient2_mailbox>
…
RCPT TO:<recipientn_mailbox>
For example:
RCPT TO:<user@rskala.com>
We’ll get a line similar to this:
250 2.1.5 user@rskala.com
After we’re finished sending our recipient list, is time to send the body content by sending the DATA command:
DATA
We’ll get a line similar to this:
354 Start mail input; end with <CRLF>.<CRLF>
Now we really begin writing our mail. The first lines you have to send are the headers, which are fields with information about the mail path and some that will be visible to the user like From, To, Cc, Subject, etc. So we begin by sending these headers like this:
From:’John Doe’<john_doe@domain.com>
To:’User’<user@rskala.com>
Subject: Hi rskala this is a test mail
You can send the From, To and Cc headers in at least three different formats. The fist includes just the name (From: user) but if the name contains a blank space you must place the whole name like ‘John Doe’. The second format includes placing just the mailbox like From:<john_doe@domain.com> and the third one is the combination of both which is the one used in our example. There are several headers you can place on this section but we are using only the most basic ones. If you need to send more headers you must place them in this section before proceeding with the body content.
Now, in order to separate the header section from the body content you must type a blank line:
[headers]
[blank line]
This is the body content and it will be visible to the user.
Regard!!
.
Consider the final syntax <ENTER>.<ENTER> which indicates the mail server the body content has ended and now the whole mail transfer operation should be considered completed. At this point the mail server will answer with a line similar to this:
250 2.6.0 <PQtt4VMW5ay00000001@hub.rskala.com> Queued mail for delivery
Now the operation has ended and we now have the choice to begin the transmission of a new mail if you start the sequence all over again with the MAIL command or finish the session by issuing the QUIT command.
QUIT
With this command we’ll get the following line and the session will be over.
221 2.0.0 hub.rskala.com Service closing transmission channel
It is possible to send any kind of mail with the steps explained here and you can use this in any automatic script, an autonomous system or simply by typing the commands one by one.
Finally here it is the whole SMTP conversation including all commands and replies shown before:
220 hub.rskala.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959
EHLO server.domain.com
250-hub.rskala.com Hello [192.168.0.89]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
MAIL FROM:<john_doe@domain.com>
250 2.1.0 john_doe@domain.com….Sender OK
RCPT TO:<user@rsakala.com>
250 2.1.5 user@rskala.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From:’John Doe'<john_doe@domain.com>
To:’User’<user@rskala.com>
Subject: Hi rskala this is a test mail
This is the body content and will be visible to the user
Regards!!
.
250 2.6.0 <pr7eIQZKt4jm00000002@rskala.com> Queued mail for delivery
QUIT
221 2.0.0 hub.rskala.com Service closing transmission channel
For more information about the rules to create, transmit and process an email you can check out our publication on The SMTP Protocol Fundamentals.
Remember to send us your questions and comments to our Twitter account: @redinskala where you’ll also find more information and security tips.
Thanks for your visit!
I’ve got some backup jobs running weekly and would like to have the log files sent to me automatically via email so I don’t have to manually check them.
On a Windows system, is there a tool that I can use that will allow me to send an email via Gmail SMTP from a command prompt?
asked Dec 8, 2009 at 6:47
Matt HansonMatt Hanson
9323 gold badges17 silver badges30 bronze badges
Gmail can be used for sending mail by any mail program and from any network.
Some command-line mail products for Windows are:
SendEmail
mailsend
(I have no first-hand experience with these products.)
See also this article : How to use Gmail as your SMTP server.
answered Dec 8, 2009 at 7:00
harrymcharrymc
431k30 gold badges495 silver badges876 bronze badges
1
Blat:
What is Blat?
Blat is a Win32 command line utility that sends eMail using SMTP or post to usenet using NNTP.
Jared Harley
12.4k3 gold badges40 silver badges51 bronze badges
answered Apr 19, 2011 at 23:17
HowToGeek demonstrates a Windows PowerShell script that works very well at How To Send Email From the Command Line in Windows Without Extra Software
Here is the method:
First you’re defining the variables:
$EmailFrom = “yourMail@gmail.com”
$EmailTo = “theRecipient’sAddress@someServer.com”
$Subject = “your subject”
$Body = “some text”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“yourGmailUsername”, “password”);
Then, you’re using this command to send the mail:
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
You’ll need a valid Gmail account in order to authenticate as a Gmail user.
answered Dec 7, 2014 at 5:26
Oz EdriOz Edri
3753 silver badges8 bronze badges
Currently in powershell we can use Send-MailMessage
cmdlet without using .NET:
$Credentials = New-Object System.Net.NetworkCredential(“yourGmailUsername”, “password”);
Send-MailMessage -From 'enterYourEmailHere ' -To 'enterRecipientMailHere' -Subject 'Email subject' -Body 'EnterBodyHere as HTML' -Attachment 'Attachment path here' -SmtpServer 'smtp.gmail.com' -Port 587 -UseSSL -BodyAsHTML -Credential $Credentials
Send-MailMessage Documentation
answered Aug 18, 2020 at 1:55
WasifWasif
7,5932 gold badges15 silver badges32 bronze badges
answered Aug 17, 2017 at 9:17
Updated on March 11, 2019
Marcus Butt / Getty Images
What could be easier than starting a new message in Windows Live Mail, Windows Mail or Outlook Express? All it takes is a click on the Create Mail button.
But what if you fancy starting a new message from a command prompt, possibly without the main window of Windows Live Mail, Windows Mail or Outlook Express showing, or if you want to create messages programmatically from other applications?
Both can be accomplished with command line arguments. You can create a simple message, but you can also specify default recipients as well as a default subject and message text.
Create a Message in Windows Live Mail, Windows Mail or Outlook Express from the Command Line
To create a new email message in Windows Live Mail, Windows Mail or Outlook Express from the Windows command line:
- For Windows Live Mail:
Type ‘«C:Program FilesWindows LiveMailwlmail» /mailurl:%‘. - For Windows Mail:
Type ‘«C:Program FilesWindows MailWinMail» /mailurl:%‘. - For Outlook Express:
Type ‘«C:Program FilesOutlook Expressmsimn» /mailurl:%‘. - Make sure you do include the inner (double) but leave out the outer (single) quotation marks.
- Hit Enter.
To create a message with default To:, Cc:, Bcc:, Subject and message body fields:
- Type ‘«C:Program FilesWindows LiveMailwlmail» /mailurl:%‘ (Windows Live Mail) ‘«C:Program FilesWindows MailWinMail» /mailurl:%‘ (Windows Mail) or ‘«C:Program FilesOutlook Expressmsimn» /mailurl:‘ (Outlook Express).
- Use the mailto URL encoder to construct a mailto: URL containing the desired default values.
For a message sent To: «recipient@example.com» by default with a Subject: of «Hello» and a body of «Hi there», the URL would be «mailto:recipient@example.com?subject=Hello&body=Hi%20there«, for example. - Copy and paste the URL to the command line, appending it immediately after «mailurl:«.
- Enter a quotation mark ‘»‘ between «mailto:» and the email address of the default recipient.
The full command line using the above example is, using Windows Live Mail, ‘«C:Program FilesWindows LiveMailwlmail» /mailurl:mailto:»recipient@example.com?subject=Hello&body=Hi%20there‘ (again including the inner but not including the outermost quotation marks).
You cannot attach files from the command line or have the message delivered automatically.
Thanks for letting us know!
Get the Latest Tech News Delivered Every Day
Subscribe
How To Send Email Locally Using Command Prompt
This article serves as a guide to test simple email functionality on your server if you are unable to access your SmarterMail interface.
- Open Windows Command Prompt using Start > Command Prompt or via Run > CMD
- Telnet to the mail server by typing telnet <domain> 25
- Once connected, we must initiate the mail sending process queue. We start this with helo <domain>
The server will reply with 250 and a hello if successful.
- Now we must set the sending mail address. Type mail from:<email address>
- Now we set the to address. Type RCPT TO:<email address>
- Type data to begin the email content.
- First we set the subject by typing Subject:<Your Subject> Then press Enter twice.
- Now type the message content of your email. When done, press Enter — Period Key — Enter to close the message.
- Type Quit to exit telnet.
- Verify your email has been received.
Article ID: 2313, Created: November 21, 2015 at 12:49 AM, Modified: November 21, 2015 at 8:13 PM
Announcement (Feb-11-2019)
If you use mailsend, please try mailsend-go. Your feedback will be appreciated.
mailsend will still be maintained (critical security fixes) but no new features will be added.
Thanks!
mailsend v1.19
mailsend is a simple command line program to send mail via SMTP protocol. Long time ago, I needed to send a piece of alert mail from a program in a networked Windows machine, but could not find a simple program like this installed. So I wrote one. You might find it useful as well. The program does not use any config file and I plan to keep it that way. From version 1.17b1+, IPv6 is supported in all platforms. Suggestions, bug reports are always welcome. If you have any question, request or suggestion, please enter it in the Issues with appropriate label.
Download source/binary
To download source/binaries, please go to the releases page.
Bug fixes and stable features are merged from dev branch to master branch every now and then. Clone the repo if you want the latest code.
Supported Platforms
-
Microsoft Windows
-
Linux/Unix
-
Mac OS X
It should compile on any POSIX compliant system. Works on 64 bit systems.
Features
Few main features:
-
ESMTP Authentication
-
IPv6 transport
-
Attachments
-
Embed images in HTML
-
Send mail to a list of users
Versions
Latest stable version is 1.19
Released on May-17-2016. Please look at: ChangeLog.
Synopsis
Version: @(#) mailsend v1.19 Copyright: BSD. It is illegal to use this software for Spamming (Compiled with OpenSSL version: OpenSSL 1.0.2f 28 Jan 2016) usage: mailsend [options] Where the options are: -copyright - show copyright information -4 - Force to use IPv4 address of SMTP server -6 - Force to use IPv6 address of SMTP server -smtp hostname/IP* - Hostname/IP address of the SMTP server -port SMTP port - SMTP port -domain domain - domain name for SMTP HELO/EHLO -t to,to..* - email address/es of the recipient/s -cc cc,cc.. - carbon copy address/es +cc - do not ask for Carbon Copy -ct seconds - Connect timeout. Default is 5 seconds -read-timeout seconds - Read timeout. Default is 5 seconds -bc bcc,bcc.. - blind carbon copy address/es +bc - do not ask for Blind carbon copy +D - do not add Date header -f address* - email address of the sender -sub subject - subject -list_address file - a file containing a list of email addresses -log file - write log messages to this file -cs character set - for text/plain attachments (default is us-ascii) -separator character - separator used with -attach. Default is comma (,) If used must be specified before -attach -enc-type type - encoding type. base64, 8bit, 7bit etc. Default is base64. Special type is "none" -aname name - name of the attachment. Default is filename -content-id id - content-id in the attachment -mime-type type - MIME type -dispostion val - "attachment" or "inline". Default is "attachment" -attach file,mime_type,[i/a] (i=inline,a=attachment) - attach this file as attachment or inline -show-attach - show attachment in verbose mode, default is no -show-mime-types - show the compiled in MIME types -M "one line msg" - attach this one line text message -content-type type - Content type. Default: multipart/mixed -msg-body path - Path of the file to include as body of mail -embed-image image - Path of image to embed in HTML -H "header" - Add custom Header -name "Full Name" - add name in the From header -v - verbose mode -V - show version info -w - wait for a CR after sending the mail -rt email_address - add Reply-To header -rrr email_address - request read receipts to this address -rp - return-path address -ssl - SMTP over SSL -starttls - use STARTTLS if the server supports it -auth - try CRAM-MD5,LOGIN,PLAIN in that order -auth-cram-md5 - use AUTH CRAM-MD5 authentication -auth-plain - use AUTH PLAIN authentication -auth-login - use AUTH LOGIN authentication -user username - username for ESMTP authentication -pass password - password for ESMTP authentication -example - show examples -ehlo - force EHLO -info - show SMTP server information -help - shows this help -q - quiet The options with * must be specified Environment variables: SMTP_USER_PASS for plain text password (-pass)
The options with asterisk must be specified. Environment variable SMTP_USER_PASS can be used to set the SMTP authentication password instead of the option -pass
How to compile/install
Linux/Unix/Mac OS X
Specify the path of OpenSSL with —with-openssl. In most Linux systems, it is installed in /usr. If OpenSSL is installed in non-standard places, type ./configure —help for options.
$ /bin/sh ./configure --with-openssl=/usr
Default installation location is /usr/local. If you want to change that:
$ /bin/sh ./configure --with-openssl=/usr --prefix=/usr/local/mailsend $ make clean $ make # make install Or $ sudo make install Or $ make install DESTDIR=/foo
The name of the binary will be mailsend. If compiled with OpenSSL, the
support for STARTTLS and SMTP over SSL will be available.
Linux Debian package
Starting from mailsend v1.18, Debian package is no longer supplied. If you want to build the Debian package yourself, after compiling mailsend, type:
$ ruby scripts/mk_debian_package.rb
To install the package, type:
$ sudo dpkg -i mailsend_1.19-ubuntu_i386.deb
To uninstall, type:
Microsoft Windows
A compiled binary with SMTP authentication support for MS Windows is already supplied. However, if you need to modify something or want to compile it yourself, you will need freely available Visual Studio from Microsoft. For Visual Studio 2015 community edition, start Developer Command Prompt for VS2015.
OpenSSL is required, if you need to compile with SMTP authentication support. Look at INSTALL.32 that comes with OpenSSL on how to compile and install OpenSSL. mailsend’s Makefile.nmake expects it to be installed at c:openssl
To compile mailsend, open a command shell and type:
c:> nmake -f Makefile.nmake clean c:> nmake -f Makefile.nmake
It compiles cleanly with cygwin as well. The name of the binary will be mailsend.exe
Known Issues
-
For text or html attachments, rn is not added at the end of lines. Some SMTP servers (e.g. qmail) does not like that. It will be fixed in some future release.
-
For non ascii characters, MIME headers are not converted as per RFC2047
-
In Windows, non ascii characters can not be entered in subject or with -M from
command line (Works fine in Linux and Mac). mailsend uses standard C
string functions and Windows versions do not know about multibyte input
from command line (Issue# 14). If anyone is familiar with it, you are welcome to implement the support, unfortunately I do not have time at this time.
FAQ
Examples
Please type: mailsend -example or look at examples
License
BSD
To display license, please type: mailsend -copyright
Copyright (C) 2001-2019 Muhammad Muquit (http://www.muquit.com/) o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. o Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. o Neither the name of the author MUHAMMAD MUQUIT (http://www.muquit.com/) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.