Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Email using CDO in HTML page

Status
Not open for further replies.

Danor

Programmer
Joined
Mar 2, 2005
Messages
2
Location
US
Hey - I was wondering if someone could point out what I'm doing wrong. I'm trying to script up a quick page to relay some emails around and it is dying halfway through on me. I threw in some alerts to see where it was dying, but now I can't figure out why. Any help would be appreciated.

Here's the code:

<HTML>
<SCRIPT language = "vbscript">


sub cmdSend_onclick
alert "0"
Set objMessage = CreateObject("CDO.Message")
alert "1"
objMessage.Subject = "Test Change Number Sender"
alert "2"
objMessage.Sender = "you@your.com"
alert "3"
objMessage.To = "me@my.com"
alert "4"
objMessage.TextBody = "These are the change numbers or random junk I put in the test text box:" & txtChanges.value & "."
alert "5"
objMessage.Configuration.Fields.Item(" = 2
alert "6"
objMessage.Configuration.Fields.Item _
(" = "myserver.smtp.com"
alert "7"
objMessage.Configuration.Fields.Item _
(" = 25
alert "8"
objMessage.Configuration.Fields.Update
alert "9"
objMessage.Send


end sub

</SCRIPT>

<BODY>
Enter Change Numbers :
<input type = "text" name = "txtChanges">
<input type = "button" value = "Send!" name = "cmdSend" align = "right">
</BODY>


It dies after alert five - the first config.fields.item dies and I can't figure out why. Thanks for any help, as VBScript isn't one of my better laguages due to disuse!
 
With a default config of your SMTP service, you can just get rid of the following lines:
objMessage.Configuration.Fields.Item(" = 2
alert "6"
objMessage.Configuration.Fields.Item _
(" = "myserver.smtp.com"
alert "7"
objMessage.Configuration.Fields.Item _
(" = 25
alert "8"
objMessage.Configuration.Fields.Update
alert "9"


Be aware that the mail server you are forwarding too might barf on .Sender = "you@your.com" .... the Exchange box here is configured not to relay messages in this way.

PS: Also check the smarthost value in your SMTP service.
 
This is what I have and it works, I don't know if you need to declare stuff at start or if you need all this but:


Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
set WShShell = WScript.CreateObject ("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Here is the subject"
objMessage.Sender = "sender@isp.com"
objMessage.To = "Recipient@isp.com"
objMessage.TextBody = "Body blah, blah"

'==============================================================================
'This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item (" = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item (" = "smtpserver"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item (" = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item (" = "myusername"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item (" = "mypassword"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
(" = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item (" = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item (" = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
 
Thanks for the help - actually, it appears the script is fine. The problem is something internal to my box - I ran it from a co-worker's PC and it runs fine. Thanks for your suggestions!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top