Link to home
Start Free TrialLog in
Avatar of keschuster
keschuster

asked on

Sending email with vbscript thru Exchange Server

I have a remote desktop that I process files on.  I'm trying to automate.  I have an account on the company exchange server no different then anyone elses.  Is it possible to send myself and email using vbscript through my exchange server account.

There isn't outlook or anything on the machine so I don't do email on that machine now - if that matters

thanks
Avatar of kieran_b
kieran_b
Flag of Australia image

Are you sending to yourself INSIDE the network?  Or to ask another way, is the exchange server you are wanting to send through responsible for the address you are sending to?

If so, then you won't need to authenticate, it will be as simple as pointing any VBScript to the Exchange server and using it like a normal SMTP server

I am no scripter, but the first link I found on doing this showed good results;

http://forums.devx.com/showthread.php?threadid=21954

As you don't have Outlook, skip suggestions 2 and 3, but 1 and 4 are good options.

Kieran
CDO works for me generally.  used from Excel.


    Set objConf = CreateObject("CDO.Configuration")
        
    With objConf.fields
      .item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
      .item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServerName
      .item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous 'cdoBasic
      '.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
      'item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
      .Update
    End With
    
    Set objMsg = CreateObject("CDO.Message")
    objMsg.Configuration = objConf
 
 
    With objMsg
 
      
      '.to = "test@qwerty.com"
      .From = "mail@zxcvbn.com.au"
      .Subject = Space(2) & Trim(tcSubject)
      .TextBody = "what"
       'use .HTMLBody to send HTML email.
  
           .AddAttachment lcAttName
      
      .fields("urn:schemas:mailheader:disposition-notification-to") = "mail@zxcvbn.com.au"
      .fields("urn:schemas:mailheader:return-receipt-to") = "mail@zxcvbn.com.au"
 
      .DSNOptions = cdoDSNSuccessFailOrDelay
      .fields.Update
      .Send
    End With
 
    Set objMsg = Nothing
    NewMail = True

Open in new window

Avatar of keschuster
keschuster

ASKER

I'm running from vbs script on my desktop within the network.

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "myemail@email.com"
objMessage.To = "myemail@email.com"
objMessage.TextBody = "This is some sample message text."
objMessage.Send

generates this error
The "SendUsing" configuration value is invalid"
Code: 80040220
Source: CDO.Message.1

Any ideas?
You need to specify the mail server you want to send the message via:

objMessage.SMTPServer = "myserver.mydomain.com"


the string can be a shortname, a FQDN, or an ip address, as long as it's routeable.
Set objMessage = CreateObject("CDO.Message")
objMessage.SMTPServer  = "server.COM"
objMessage.Subject = "Example CDO Message"
objMessage.From = "email@email.com"
objMessage.To = "email@email.com"
objMessage.TextBody = "This is some sample message text."
objMessage.Send


Now I get error - Object doesn't support this property or method:'objMessage.smtpserver'
oops, my bad.  .SMTPServer is a property of the CDO configuration, not the message.  you'd need to specify that first.  I'd write the code for you but robberbaron already has.  Look at lines 1-13 on the script he posted.  Those should work for you (modified for your needs of course)
I found solution using activex
google Chilkat
AspEmail does the same sort of thing. It has a freeware component. chilkat is not.

CDO is lower level than these and is MS download for use with Exchange.
"CDO is lower level than these and is MS download for use with Exchange."

for use with exchange?  Were do I get more information on this?  I can use this to send email via BAT file for VBS?
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I get an error message on line 65
"The Server rejected one or more recipient addresses.  the server reponse was:550 5.7.1. Unable to relay for Keithschsuter@gmail.com

I'm running this on the company network and pointing to the exchange server.
Any ideas?
I changed authentication to = 2 and it WORKED!!!
Thanks