Scripting question - sending email using CDOSYS

G

Guest

I am trying to create a script that will send an email using CDOSYS. I have
listed the code in the .vbs script below. Can anyone see a problem with this
script? It is not sending emails. If this is the wrong forum please let me
know which is the correct forum to post this question. Please note that all
NewMail.Configuration.Fields.Item entries are on one line, not two. Also, the
password is set to "" for an empty string because this particular temp user
does not have a password. Here is the code:

On Error Resume Next
RCP = "(e-mail address removed)"
FROM = "(e-mail address removed)"
SUB = "System Restart"
MSG = "This system was successfully restarted."

Set NewMail = CreateObject("CDO.Message")
NewMail.Subject = SUB
Newmail.Sender = FROM
NewMail.To = RCP
NewMail.TextBody = MSG

NewMail.Configuration.Fields.Item
_("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

NewMail.Configuration.Fields.Item
_("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"192.168.1.18"

NewMail.Configuration.Fields.Item
_("http://schemas.microsoft.com/cdo/configuration/authenticate") = 1

NewMail.Configuration.Fields.Item
_("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user2"

NewMail.Configuration.Fields.Item
_("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""

NewMail.Configuration.Fields.Item
_("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

NewMail.Configuration.Fields.Update

NewMail.Send
 
D

David H. Lipman

From: "Candace" <[email protected]>

| I am trying to create a script that will send an email using CDOSYS. I have
| listed the code in the .vbs script below. Can anyone see a problem with this
| script? It is not sending emails. If this is the wrong forum please let me
| know which is the correct forum to post this question. Please note that all
| NewMail.Configuration.Fields.Item entries are on one line, not two. Also, the
| password is set to "" for an empty string because this particular temp user
| does not have a password. Here is the code:
|
| On Error Resume Next
| RCP = "(e-mail address removed)"
| FROM = "(e-mail address removed)"
| SUB = "System Restart"
| MSG = "This system was successfully restarted."
|
| Set NewMail = CreateObject("CDO.Message")
| NewMail.Subject = SUB
| Newmail.Sender = FROM
| NewMail.To = RCP
| NewMail.TextBody = MSG
|
| NewMail.Configuration.Fields.Item
| _("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
|
| NewMail.Configuration.Fields.Item
| _("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
| "192.168.1.18"
|
| NewMail.Configuration.Fields.Item
| _("http://schemas.microsoft.com/cdo/configuration/authenticate") = 1
|
| NewMail.Configuration.Fields.Item
| _("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user2"
|
| NewMail.Configuration.Fields.Item
| _("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
|
| NewMail.Configuration.Fields.Item
| _("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
|
| NewMail.Configuration.Fields.Update
|
| NewMail.Send

Here's a better place for the post, a Scripting News Group.

microsoft.public.windows.server.scripting
 
J

Jon

You can't use "SUB" as a variable name.

You can also comment out the first line (with an apostrophe at the
beginning) to see error messages

So change these 2 lines
SUB = "System Restart"
NewMail.Subject = SUB

eg to
SUB1 = "System Restart"
NewMail.Subject = SUB1


2 good newsgroups to post to
microsoft.public.scripting.wsh
microsoft.public.scripting.vbscript

Jon
 
P

Paul Johnson

Note: SUB is a reserved word (used for Subroutines)

SUB = "System Restart"

Paul
 
P

Paul Johnson

Also found this on the web
Now from David This might be too specific an issue, but I'll mention it
anyway. Setting SmtpMail.SmtpServer using the server name gives:
Could not access 'CDO.Message' object.
innerexception: The transport failed to connect to the server.
Setting SmtpMail.SmtpServer using the IP address gives:
Could not access 'CDO.Message' object.
innerexception: The message could not be sent to the SMTP server. The
transport
error code was 0x800ccc15. The server response was not available
I tracked this issue down to McAfee VirusScan Enterprise 8.0 VirusScan
Console, Access Protection, Properties, Port-Blocking tab, Rule:"Prevent
mass mailing worms from sending mail" This blocks outbound access to any
port 25 on the network. Edit button shows a list of excluded processes to
which new processes can be added.

Regards,
DavidG
 
G

Guest

I commented out the first line so that I could see the error messages, but
they go by so fast I can't read them. What line of code could I use to force
the screen to command window to remain open after the script runs or to copy
output to a text file?
 
J

Jon

Assuming you're running it as a standalone script, then you could set your
default script engine to WScript

Start > run > cmd > wscript //H:WScript
This should cause error messages to pop up in message box


To make the command line CScript the default engine, once again
Start > run > cmd > wscript //H:CScript


Jon
 
G

Guest

Okay. I am getting the following error message when I try to run the script:

"The message could not be sent to the SMTP server. The transport error code
was 0x800ccc6f. The server response was 554 5.1.0 Sender Denied"

I made some suggested changes to the code. (See below).

'On Error Resume Next
RCP = "(e-mail address removed)"
FROM = "(e-mail address removed)"
SUBJ = "System Restart"
MSG = "This system was successfully restarted."

Set NewMail = CreateObject("CDO.Message")
NewMail.Subject = SUBJ
Newmail.Sender = FROM
NewMail.To = RCP
NewMail.TextBody = MSG

NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.1.18"

NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/authenticate") = 1

NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "candacef"

NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "start2"

NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

NewMail.Configuration.Fields.Update

NewMail.Send
 
J

Jon

I'm not familiar with using that particular object, to send emails, so I
can't advise any further on that.

It sounds like your script is working ok, in terms of syntax etc, but
whether you are using the object in the correct way, I do not know.

Would suggest googling to examine other threads, where that object is used,
and looking at other people's examples / solutions to problems.

http://www.google.com/search?as_q=&...as_dt=i&as_sitesearch=&as_rights=&safe=active


Failing that posting in one of the previously mentioned newsgroups, might
give you a better response


Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top