Solved

Script to send confirmation e-mail not working

Posted on 2007-03-29
6
1,059 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:desmondg
6 Comments
 

Author Comment

by:desmondg
ID: 18820429
I put a response.write err.description and gets the error
"The transport failed to connect to the server."  Any ideas anyone.
0
 
LVL 6

Expert Comment

by:DocGyver
ID: 18867299
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.
0
 

Author Comment

by:desmondg
ID: 19190006
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.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20634014
PAQed with points refunded (250)

Computer101
EE Admin
0
 

Expert Comment

by:Trindaz
ID: 21843392
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

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now