[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1290
  • Last Modified:

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
0
JSmales
Asked:
JSmales
1 Solution
 
usankarCommented:
check if the mails are getting queued up(QUEUE folder) or going to the bad mails folder(BADMAIL)
0
 
af500Commented:
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
%>
0
 
JSmalesAuthor Commented:
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
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
JSmalesAuthor Commented:
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
%>
0
 
JSmalesAuthor Commented:
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.
0
 
CetusMODCommented:
Question PAQ'd
500 points refunded.

CetusMOD
Community Support Moderator
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now