Saturday, November 19, 2005

It's in the Mail

You know, it's not so hard to send e-mail from VBScript. I guess I just figured it would be given my experience with Perl and batch files.

All that is needed is Outlook Express. I finally found a good reason to have OE installed by default.

Function SendEMail(sSender, sTo, sSubject, sTextBody, sFrom, sFile, sSMTPServer)
  Dim objEmail
  Set objEmail = CreateObject("CDO.Message")
  objEmail.Sender = sSender
  objEmail.To = sTo
  objEmail.Subject = sSubject
  objEmail.TextBody = sTextBody
  objEmail.From = sFrom
  objEmail.AddAttachment(sFile)
  objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPServer
  objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  objEmail.Configuration.Fields.Update
  objEmail.Send
End Function

No comments: