Solved sending email in batch file

June 11, 2013 at 01:01:59
Specs: Windows 7
I have tablespace utilization report which to be sent automatic email for this how can we write batch file.

See More: sending email in batch file

Report •


✔ Best Answer
June 11, 2013 at 08:15:43
Here's the sample script I wrote back when I was figuring out how to do it. The script has some problems when you mix Win2K and some versions of Office. Something about Office replacing the CDO.Message object with its own. VBScript can still send email, but you need to wrap the script in a .wsf file. Official documentation is found on MSDN.
Const emailTo    = "you@some.com"
Const emailFrom  = "me@some.com"
Const emailSbjct = "Subject"
Const SMTPServer = "smtp.some.com"
Const SMTPPort   = 25
Const emailUsr   = "me@some.com"
Const emailPsswd = "pass"
Const emailSSL   = False
      emailMsg   = "Message"

Const cfg = "http://schemas.microsoft.com/cdo/configuration/"
With CreateObject("CDO.Message")
  .From                                  = emailFrom
  .To                                    = emailTo
  .Subject                               = emailSbjct
  .TextBody                              = emailMsg
  With .Configuration.Fields
    .Item(cfg & "sendusing")             = 2
    .Item(cfg & "smtpserver")            = SMTPServer
    .Item(cfg & "smtpserverport")        = SMTPPort
    .Item(cfg & "smtpconnectiontimeout") = 60
    .Item(cfg & "smtpauthenticate")      = 1
    .Item(cfg & "smtpusessl")            = emailSSL
    .Item(cfg & "sendusername")          = emailUsr
    .Item(cfg & "sendpassword")          = emailPsswd
    .Update
  End With
  .Send
End With

How To Ask Questions The Smart Way



#1
June 11, 2013 at 07:01:38
You need a command line mailer and you need to know the syntax.

=====================
M2 Golden-Triangle


Report •

#2
June 11, 2013 at 07:47:54
What Mechanix2Go said. VBScript or PowerShell can send email, but batch requires a third party program.

How To Ask Questions The Smart Way


Report •

#3
June 11, 2013 at 07:54:37
Hi R2,

Got a link to a cheat sheet for VBS mailing?

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
June 11, 2013 at 08:15:43
✔ Best Answer
Here's the sample script I wrote back when I was figuring out how to do it. The script has some problems when you mix Win2K and some versions of Office. Something about Office replacing the CDO.Message object with its own. VBScript can still send email, but you need to wrap the script in a .wsf file. Official documentation is found on MSDN.
Const emailTo    = "you@some.com"
Const emailFrom  = "me@some.com"
Const emailSbjct = "Subject"
Const SMTPServer = "smtp.some.com"
Const SMTPPort   = 25
Const emailUsr   = "me@some.com"
Const emailPsswd = "pass"
Const emailSSL   = False
      emailMsg   = "Message"

Const cfg = "http://schemas.microsoft.com/cdo/configuration/"
With CreateObject("CDO.Message")
  .From                                  = emailFrom
  .To                                    = emailTo
  .Subject                               = emailSbjct
  .TextBody                              = emailMsg
  With .Configuration.Fields
    .Item(cfg & "sendusing")             = 2
    .Item(cfg & "smtpserver")            = SMTPServer
    .Item(cfg & "smtpserverport")        = SMTPPort
    .Item(cfg & "smtpconnectiontimeout") = 60
    .Item(cfg & "smtpauthenticate")      = 1
    .Item(cfg & "smtpusessl")            = emailSSL
    .Item(cfg & "sendusername")          = emailUsr
    .Item(cfg & "sendpassword")          = emailPsswd
    .Update
  End With
  .Send
End With

How To Ask Questions The Smart Way


Report •

#5
June 13, 2013 at 02:34:55
Using Powershell
Send-MailMessage -smtp $smtp -from $from -to $to -subject $subject -body $body -Attachments $dest

Report •

#6
June 14, 2013 at 08:04:40
PowerShell makes many things easier, except running scripts and running programs.

How To Ask Questions The Smart Way


Report •

Ask Question