Sending mail from a batch file

We have a script for backing up files. Upon completion of the backup operation, we would like to send the report as an email notification to some of our email addresses.

How can I do that?

+44
command-line windows email-client batch-file
Apr 02 '09 at 13:09
source share
8 answers

Blat :

blat -to user@example.com -server smtp.example.com -f batch_script@example.com -subject "subject" -body "body" 
+32
Apr 02 '09 at 13:42
source share

You can also use Power Shell script:

 $smtp = new-object Net.Mail.SmtpClient("mail.example.com") if( $Env:SmtpUseCredentials -eq "true" ) { $credentials = new-object Net.NetworkCredential("username","password") $smtp.Credentials = $credentials } $objMailMessage = New-Object System.Net.Mail.MailMessage $objMailMessage.From = "script@mycompany.com" $objMailMessage.To.Add("you@yourcompany.com") $objMailMessage.Subject = "eMail subject Notification" $objMailMessage.Body = "Hello world!" $smtp.send($objMailMessage) 
+20
Apr 29 '09 at 21:42
source share

PowerShell has a built-in command . So work directly from the .bat file:

 powershell -ExecutionPolicy ByPass -Command Send-MailMessage ^ -SmtpServer server.address.name ^ -To someone@what.ever ^ -From noreply@possibly.fake ^ -Subject Testing ^ -Body 123 

NB -ExecutionPolicy ByPass is required only if you have not configured permissions to start PS from CMD

Also for those who want to call it from powershell, drop everything up to -Command [inclusive], and ` will be your escape character (not ^ )

+9
Jul 27 '16 at 5:10
source share

bmail . Just install the exe and run the following line:

 bmail -s myMailServer -f Sender@foo.com -t receiver@foo.com -a "Production Release Performed" 
+8
Apr 02 '09 at 13:12
source share

The easiest way is to use a third-party application mentioned by others.

If this is not an option, I wrote a simple sendmail utility using vbscript and CDO, which I called from the script package

See examples here http://www.paulsadowski.com/WSH/cdo.htm

+5
Apr 2 '09 at 14:11
source share

We use blat to do this all the time in our environment. I also use it to connect to Gmail with Stunnel . Here are the options for sending the file

 blat -to user@example.com -server smtp.example.com -f batch_script@example.com -subject "subject" -body "body" -attach c:\temp\file.txt 

Or you can put this file in the body

 blat c:\temp\file.txt -to user@example.com -server smtp.example.com -f batch_script@example.com -subject "subject" 
+3
Apr 02 '09 at 15:10
source share

You can also use sendmail . I use it in this subversion cache to send email notifications: post-commit hook

+3
Jun 08 2018-11-18T00:
source share

There are several methods to solve this problem.

My advice is to use the powerful free Windows SendEmail console application.

 sendEmail.exe -f sender.from@mail.com -o message-file=body.txt -u subject message -t to.email.address@mail.com -a attachment.zip -s smtp.gmail.com:446 -xu gmail.login -xp gmail.password 
+1
Jul 03 '14 at 2:46
source share



All Articles