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 = "http://schemas.microsoft.com/cdo/configuration/" 
	
	Set cdoConfig = CreateObject("CDO.Configuration") 
	
	With cdoConfig.Fields 
		.Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
		.Item(sch & "smtpserver") = "exchangeserver" 
		.Item(sch & "smtpserverport") = 25 
		.update 
	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 
		.Send 
	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
LogFile.Close 

EmailSend "email@address.com,email2@address.com","ccemail@address.com","bccemail@address.com","fromemail@address.com","Email Subject",Content

One comment

Leave a Reply