Link to home
Start Free TrialLog in
Avatar of desmondg
desmondg

asked on

Script to send confirmation e-mail not working

I am using the following script which I got off the internet to send a confirmation e-mail to clients after they have filled in my form.  The problem is that though the script report no errors the e-mails are not received and may well not be sent.  Is there someway I can tell whether the e-mails are at least sent?  What could the problem possibly be?

Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoSendUsingExchange = 3

Const cdoAnonymous = 0
Const cdoBasic = 1
Const cdoNTLM = 2

'Sends an email To aTo email address, with Subject And TextBody.
'The email is In text format.
'Lets you specify BCC adresses, Attachments, smtp server And Sender email address

  on error resume Next

  Dim Message 'As New CDO.Message '(New - For VBA)
 
  'Create CDO message object
  Set Message = CreateObject("CDO.Message")

  'Set configuration fields.
  With Message.Configuration.Fields
    'Original sender email address
    .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = "myemail@yahoo.com"

    'SMTP settings - without authentication, using standard port 25 on host smtp
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.btl.net"

    'SMTP Authentication
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

    .Update
  End With

  'Set other message fields.
  With Message
    'From, To, Subject And Body are required.
    .From = "myemail@yahoo.com"
    .To = "myemail@yahoo.com"
    .Subject = "Land Registry Application re Parcel " + request.form("PARCELNO") + "in Reg. Section " + request.form("REG_SECTION")

    'Set TextBody property If you want To send the email As plain text
    .TextBody = "This is to confirm receipt of your application(s)."

    'Set HTMLBody  property If you want To send the email As an HTML formatted
    '.HTMLBody = TextBody

    'Blind copy And attachments are optional.
    'If Len(BCC)>0 Then .BCC = BCC
    'If Len(Files)>0 Then .AddAttachment Files
   
    'Send the email
       response.write("before sending")
    .Send
    response.write("after sending")
  End With

  'Returns zero If succesfull. Error code otherwise
  SendMailByCDO = Err.Number
Avatar of desmondg
desmondg

ASKER

I put a response.write err.description and gets the error
"The transport failed to connect to the server."  Any ideas anyone.
Next thing I'd try is to attemt to telnet to port 25 on the smtp.btl.net machine from the machine where the code has to run.  If you get a response then send the QUIT command to disconnect.  Doing so will at least see if you can connect and issue a simple command.

If that works then you should try to send an email manually. To do this telnet to port 25 again and issue the following commands changing for appropriate email addresses in case it works:

telnet smtp.btl.net 25
HELO localhost
MAIL FROM: my@mydomain.tld
RCPT TO: guytosendto@his.domain.tld
DATA
put some things to send here
and finish with a line with a single dot (.) on a line by itself
.
QUIT

You may not have to issue the QUIT depending on how the server is configured.  Let me know what results you get with that.  Then we can diagnose the CDO stuff in your VB code.
After we changed our DSL provider I was surprised to find that e-mails were filling my in-box from this application.  

I have tried DocGyver's experiments since and was able to send e-mails using telnet.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America 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 know points have been refunded already but...

Is your SMTP server configured to allow for anonymous sending of emails? This might explain why email sending works from your email client, but not from the script, and would explain why you can't connect to the server.

The line specifying anonymous sending copied below (change to what I'm not exactly sure)
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

Open in new window