Search code examples
windowsemailbatch-filesmtpblat

Send email from a batch script. Blat doesn't work


I need to send an email from a batch script. I tried several solutions without success.

For example, with Blat:

:send_mail
"\Program Files (x86)\blat275\full\blat.exe" 
    -server smtp.gmail.com
    -port 525
    -f [email protected]
    -to [email protected] 
    -s "hello"
    -body "world"

When I run the script, I just get a Windows crash:

A Win32 command line eMail tool stopped working

Does someone have a better solution?

EDIT & SOLUTION

I tried on our server (with our smtp) and it worked with Blat. See the full code in my answer below.


Solution

  • With Blat on my server:

    SET [email protected],[email protected]
    
    SET server=127.0.0.1
    SET port=25
    SET [email protected]
    SET subject="BACKUP PROBLEM"
    
    SET year=%DATE:~6,4%
    SET month=%DATE:~3,2%
    SET day=%DATE:~0,2%
    SET today=%year%-%month%-%day%
    
    "\Program Files (x86)\blat275\full\blat.exe" -server %server% -port %port% -f %from% -to %to% -html -s %subject% -body "%today%: bla bla bla"