How to send email in VBScript via Exchange Server

Hello,

I need a script which will allow me to send email to recipient. Currently i am using Office 2013 and it's Exchange Server. I created a vbscript but it seems that it throwing me an error :-

ActiveX component can't create object: 'Outlook.Application'

The code that i used is given below. For security purpose, i have replaced my company name with the string "domain.com".

Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
strEmailAddr  = "xyz@domain.com"
objMailItem.Recipients.Add strEmailAddr
objMailItem.Body = "Hi"
objMailItem.Send
Set objMailItem = nothing
Set objOutl = nothing

Can anybody please help me out with the script.

Regards,

agm7883

June 18th, 2015 7:50am

This is what I use.  Now I should add that I only run this from my server so I have Exchange setup to relay these messages anonymously.

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Account Lockout" 
objMessage.From = "From@e-mailaddress.com" 
objMessage.To = "to@e-mailaddress.com.com" 
objMessage.TextBody = "Bodyofthemessage" 

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server.fqdn.name"

'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update

objMessage.Send
End If

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2015 7:55am

Hello,

I am using Exchange Server. if i open Outlook 2013 -> File -> Info -> Account Setting -> Account Settings, i get the "Email" tab. Under it, i have my profile created. It's "Type" is Microsoft Exchange.

So can i have some script which will connect through Exchange Server not SMTP server.

Regards,

agm7883

June 18th, 2015 9:40am

Please read this:
Missing registry information can cause problems with the Outlook object model

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2015 3:21pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics