Windows XP
(1)
Outlook
(1)
VB
(1)
Configuration.Fields.Update
(1)
Configuration.Fields
(1)
AddAttachment
(1)
CreateObject
(1)
SomePassword
(1)

Sending an email message from a batch vbs script

Asked By Marius - Roma
27-Jan-10 04:01 PM
I need to create a vbscript to be scheduled as a batch job to send a
specific file to a given recipient every night.
Outlook is installed on the Windows XP Pc where the script should be
scheduled, but no user interaction is available (the script should be
scheduled to run during the night).
What is the best method I should use to create and send the message?
Is there any sample I can start from?
Regards
Marius

"Marius - Roma" <mr@nospam.

Pegasus [MVP] replied to Marius - Roma
27-Jan-10 06:04 PM
If you want a batch solution then blat.exe (which you can download from a
number of sites) is the simplest solution to send an EMail message.

If you want a VB Script file then you could do it like so:

const cdoBasic=1
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set objEmail = CreateObject("CDO.Message")
With objEmail
.From = "James@company.com"
.To = "Jim@company.com"
.Subject = "Test Mail"
.Textbody = "The quick brown fox " & Chr(10) & "jumps over the lazy dog"
.AddAttachment "d:\Testfile.txt"
With .Configuration.Fields
.Item (schema & "sendusing") = 2
.Item (schema & "smtpserver") = "mail.company.com"
.Item (schema & "smtpserverport") = 25
.Item (schema & "smtpauthenticate") = cdoBasic
.Item (schema & "sendusername") = "James@company.com"
.Item (schema & "smtpaccountname") = "James@company.com"
.Item (schema & "sendpassword") = "SomePassword"
End With
.Configuration.Fields.Update
.Send
End With

Neither the batch file nor the VB Script file solution relies on Outlook or
any other local mail client.

CDO refinement

Frank Van Staveren replied to Pegasus [MVP]
03-Feb-10 06:10 AM
That works, but I wondering how to send an appointment/meeting using the smae methods, with an ics attachment.  I cdan deo the attachment, but the headers read email on the receiving end, not as a calendar item.  How do I change it?
Post Question To EggHeadCafe