Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

Send an Email with VBScript

Another really easy script. This script will send an email. As I automate tasks, I like to build an html log file and email the results of the script. You can also send an email as text.

' The following procedure will take an email address and content and complete an email
Sub EmailSend(EmailAddressTo,EmailAddressCc,EmailAddressBcc,EmailAddressFrom,Subject,Content)
	' Send the email report
	Dim cdoMessage, cdoConfig, sch: sch = "" 
	Set cdoConfig = CreateObject("CDO.Configuration") 
	With cdoConfig.Fields 
		.Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
		.Item(sch & "smtpserver") = "exchangeserver" 
		.Item(sch & "smtpserverport") = 25 
	End With 
	Set cdoMessage = CreateObject("CDO.Message") 
	With cdoMessage 
		Set .Configuration = cdoConfig 
		.From = EmailAddressFrom 
		.To = EmailAddressTo 
		.Cc = EmailAddressCc
		.Bcc = EmailAddressBcc
		.Subject = Subject
		.HTMLBody = Content
		'.TextBody = Content 
	End With 
	' Cleanup
	Set cdoMessage = Nothing 
	Set cdoConfig = Nothing 
End Sub

This code will call the sub:

Set LogFile = objFSO.OpenTextFile(sCurPath & "\Logs\" & LogFileName, 1)
Content = LogFile.ReadAll

EmailSend ",","","","","Email Subject",Content