Link to home
Start Free TrialLog in
Avatar of JSmales
JSmales

asked on

Sending mail with ASP on Win2K3 IIS6, SMTP

Hi,
I am trying to send an email from an ASP page running on Windows 2003. I am moving a site from jsp/linux to asp/windows, and have not used SMTP (IIS) on windows before. I have installed SMTP and it is running. When I run my script I get this error:

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.
/en/mail2.asp, line 19         {MyMail.Send() - see below}

This is the code
<%
Dim MyMail
Set MyMail = Server.CreateObject("CDO.Message")
MyMail.From = "josh@golfbox.com.au"
MyMail.To = "josh@golfbox.com.au"
MyMail.Subject = "Test email"
MyMail.TextBody = "Test email"
MyMail.Fields("urn:schemas:httpmail:importance").Value = 2
MyMail.Fields.Update()
MyMail.Send()
Set MyMail = Nothing
%>

I have also tried this code (which I found on this site).

<%
strMailBody="<Font Color=Red><B>Test HTML String</B></Font>"
CALL SendMailCDOSYS("josh@golfbox.com.au","josh@golfbox.com.au","test",strMailBody,True,"localhost")

Sub SendMailCDOSYS(strFrom,strTO,strSubject,strMailBody,blnHTML,sMailServer)
On Error Resume Next
     Dim objCDOConf,objCDOSYS
     ' ** CREATE THE E-MAIL SERVER OBJECT **
     Set objCDOSYS = Server.CreateObject("CDO.Message")
     Set objCDOConf = Server.CreateObject ("CDO.Configuration")

     ' ** SET AND UPDATE FIELDS PROPERTIES **
     With objCDOConf
          ' ** OUT GOING SMTP SERVER **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer
          ' ** SMTP PORT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")  = 25
          ' ** CDO PORT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          ' ** TIMEOUT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
          .Fields.Update
     End With

     ' ** UPDATE THE CDOSYS CONFIGURATION **
     Set objCDOSYS.Configuration = objCDOConf

     With objCDOSYS    
          ' ** WHO THE E-MAIL IS FROM **
          .From = strFrom

          ' ** WHO THE E-MAIL IS SENT TO **
          .To = strTo
                   
          ' ** THE SUBJECT OF THE E-MAIL **
          .Subject = strSubject
           
          ' ** SET THE E-MAIL BODY FORMAT (HTMLBody=HTML TextBody=Plain) **
          If blnHTML = True Then
          .HTMLBody = strMailBody
          Else
          .TextBody = strMailBody
          End If
           
          ' ** SEND THE E-MAIL **
          .Send
     End with                    
       
     ' ** CLOSE THE SERVER MAIL OBJECT **
     Set objCDOSYS = Nothing
End Sub
%>

This code does not return an error but it does not send any emails either. The mail directories in C:\Inetpub\mailroot\ are all empty.

I only need to send emails from the server. The machine is currently on the local network (192.168.1.4), while I am working on the site. It is a new (2 week old) machine. I think the SMTP may not be configured correctly.

Any suggestions?

Joshua
Avatar of usankar
usankar

check if the mails are getting queued up(QUEUE folder) or going to the bad mails folder(BADMAIL)
is the asp is running on the same server as the SMTP ... try JUST this:
<%
Dim MyMail
Set MyMail = Server.CreateObject("CDO.Message")
MyMail.From = "josh@golfbox.com.au"
MyMail.To = "josh@golfbox.com.au"
MyMail.Subject = "Test email"
MyMail.TextBody = "Test email"
MyMail.Send()
Set MyMail = Nothing
%>
Avatar of JSmales

ASKER

The queue folder & bad mails folder are both empty.

The ASP and SMTP are on the same server. When I try:

<%
Dim MyMail
Set MyMail = Server.CreateObject("CDO.Message")
MyMail.From = "josh@golfbox.com.au"
MyMail.To = "josh@golfbox.com.au"
MyMail.Subject = "Test email"
MyMail.TextBody = "Test email"
MyMail.Send()                        <-- Line 16
Set MyMail = Nothing
%>

It returns:

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.
/en/mail3.asp, line 16
Avatar of JSmales

ASKER

Ok, I have manually tested the SMTP server using

http://support.microsoft.com/default.aspx?scid=kb;en-us;323350

and this adds an email to the queue folder. When I run the script below, an email is added to the queue folder, but is not sent.

<%
strMailBody="<Font Color=Red><B>Test HTML String</B></Font>"
CALL SendMailCDOSYS("josh@golfbox.com.au","josh@golfbox.com.au","test",strMailBody,True,"localhost")

Sub SendMailCDOSYS(strFrom,strTO,strSubject,strMailBody,blnHTML,sMailServer)
On Error Resume Next
     Dim objCDOConf,objCDOSYS
     ' ** CREATE THE E-MAIL SERVER OBJECT **
     Set objCDOSYS = Server.CreateObject("CDO.Message")
     Set objCDOConf = Server.CreateObject ("CDO.Configuration")

     ' ** SET AND UPDATE FIELDS PROPERTIES **
     With objCDOConf
          ' ** OUT GOING SMTP SERVER **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer
          ' ** SMTP PORT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")  = 25
          ' ** CDO PORT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          ' ** TIMEOUT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
          .Fields.Update
     End With

     ' ** UPDATE THE CDOSYS CONFIGURATION **
     Set objCDOSYS.Configuration = objCDOConf

     With objCDOSYS    
          ' ** WHO THE E-MAIL IS FROM **
          .From = strFrom

          ' ** WHO THE E-MAIL IS SENT TO **
          .To = strTo
                   
          ' ** THE SUBJECT OF THE E-MAIL **
          .Subject = strSubject
           
          ' ** SET THE E-MAIL BODY FORMAT (HTMLBody=HTML TextBody=Plain) **
          If blnHTML = True Then
          .HTMLBody = strMailBody
          Else
          .TextBody = strMailBody
          End If
           
          ' ** SEND THE E-MAIL **
          .Send
     End with                    
       
     ' ** CLOSE THE SERVER MAIL OBJECT **
     Set objCDOSYS = Nothing
End Sub
%>
Avatar of JSmales

ASKER

Ok, I manage to solve the problem. I was trying to send the email to a local network address, that was not setup in our internal DNS. I have been able to send externally, it just did not occur to try until now.

I am using  SendMailCDOSYS code to send the emails.
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands 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