I'm running Windows 2003 Service Pack 2. I have a batch file that runs on demand. I want to have an email sent every time the batch file runs. The email is simple, just a sentence indicating that the batch file ran; it is the same every time. I've tried a couple of things to get this done. I thought of telnet, but I can't figure out how to redirect a set of commands into telnet; Windows batch files don't have a Unix-style "here document," and calling "telnet
There is no directory \Inetpub\mailroot\pickup, so the pickup method doesn't work. I'm not allowed to install any software on the machine, so the blat method doesn't work. I don't want to do this manually, so the telnet method doesn't work. And I don't have ASP, so that method doesn't work. Any other ideas?
Commented Jan 27, 2012 at 19:46 possible duplicate of sending mail from Batch file – user565869 Commented Aug 18, 2015 at 17:00Max is on he right track with the suggestion to use Windows Scripting for a way to do it without installing any additional executables on the machine. His code will work if you have the IIS SMTP service setup to forward outbound email using the "smart host" setting, or the machine also happens to be running Microsoft Exchange. Otherwise if this is not configured, you will find your emails just piling up in the message queue folder (\inetpub\mailroot\queue). So, unless you can configure this service, you also want to be able to specify the email server you want to use to send the message with. To do that, you can do something like this in your windows script file:
Set objMail = CreateObject("CDO.Message") Set objConf = CreateObject("CDO.Configuration") Set objFlds = objConf.Fields objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.your-site-url.com" 'your smtp server domain or IP address goes here objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email 'uncomment next three lines if you need to use SMTP Authorization 'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username" 'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password" 'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic objFlds.Update objMail.Configuration = objConf objMail.FromName = "Your Name" objMail.From /cdn-cgi/l/email-protection" data-cfemail="1b62746e695b7a7f7f697e686835787476">[email protected]" objMail.To /cdn-cgi/l/email-protection" data-cfemail="6e0a0b1d1a07000f1a0701002e0f0a0a1c0b1d1d400d0103">[email protected]" objMail.Subject = "Email Subject Text" objMail.TextBody = "The message of the email. " objMail.Send Set objFlds = Nothing Set objConf = Nothing Set objMail = Nothing
answered Jan 27, 2012 at 20:45
1,932 3 3 gold badges 26 26 silver badges 35 35 bronze badges
This works. Thank you! And thanks to everyone else who responded.
Commented Jan 27, 2012 at 21:01
'objFlds.Item' is not recognized as an internal or external command, operable program or batch file.
Commented Sep 19, 2018 at 10:16
Do I run this whole script on cmd prompt only? I have the same problem as @SunilChaudhary. I get the same error for all i.e., also for objMail.TextBody, objMail.Send, objMail.From and so on
Commented Sep 22, 2021 at 12:13@dmarietta How did you run this? On cmd? Do I have something installed on PC to run this? I get the errors 'objMail.Configuration' is not recognized as an internal or external command, operable program or batch file. Also for all objFlds.Item, objMail.FromName, objMail.From, objMail.To, objMail.Subject and so on
Commented Sep 22, 2021 at 12:18@Priya These would be run in a Windows Script file. Put them in a .VBS file to create a Windows Script file. These are not CommandLine commands. These run in windows script which is available on all versions of Windows OS back to Windows 2000.