Send mail from a Windows script Send mail from a Windows script windows windows

Send mail from a Windows script


It is possible with Wscript, using CDO:

Dim objMailSet objMail = CreateObject("CDO.Message")objMail.From = "Me <Me@Server.com>"objMail.To = "You <You@AnotherServer.com>"objMail.Subject = "That's a mail"objMail.Textbody = "Hello World"objMail.AddAttachment "C:\someFile.ext"---8<----- You don't need this part if you have an active Outlook [Express] account -----' Use an SMTP serverobjMail.Configuration.Fields.Item _    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2' Name or IP of Remote SMTP ServerobjMail.Configuration.Fields.Item _    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _    "smtp.server.com"' Server port (typically 25)objMail.Configuration.Fields.Item _    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25objMail.Configuration.Fields.Update----- End of SMTP usage ----->8---objMail.SendSet objMail=NothingWscript.Quit

Update: found more info there: VBScript To Send Email Using CDOBy default it seems it uses Outlook [Express], so it didn't worked on my computer but you can use a given SMTP server, which worked fine for me.


I don't know if dropping a binary alongside the .bat file counts as installing software, but, if not, you can use blat to do this.


If the server happened (I realize how old this question is) to have Powershell v2 installed, the CmdLet Send-MailMessage would do this in one line.

Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotficationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]