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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Problems 1

Status
Not open for further replies.

bodmin

Technical User
Apr 1, 2004
98
GB
Having troubles with this page its supposed to display a form and then collect that form data and compose and send email containing that data.

The page will not display, the page uses the following code

<% @LANGUAGE =VBScript %>
<%
Option Explicit
Response.Buffer

Dim strEmail, strSubject, strMessage, objMail, strSql, objConn, strConnection
Dim objRS, strCMail, strSPMail

strCMail = Trim(Request("cmail"))

if (Request.ServerVariables("message") = " ") Then
%>

<html>

<head>
<title>Send Mail To Customer</title>
<link rel="stylesheet" type="text/css" href="mainstyle.css">
</head>

<body bgcolor ="blue">
<center>
<br>
<img bgcolor ="blue" border ="0" height ="150" width ="700" src ="images/title.bmp">
<br>
<br>
<hr>
<br>
<H3>Please use the form below to send an email to this projects customer</H3>
</center>
<br>
<br>
<form action ="mailcustomer.asp" method ="post">
Subject : <input name ="subject" type ="Text" size ="40"><br><br>
Message : <textarea name ="message" rows ="10" cols="65">
Please input your message here
</textarea>
<br>
<input type ="Submit" value ="Send Mail">
</form>
<br>
<address>
Copyright Smith Information Solutions 2004
</address>
</body>
</html>

<%

Else

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection ="DSN=allocation;Database=allocation;"
objConn.Open strConnection

Set objRS = Server.CreateObject("ADODB.Recordset")

strSql ="select ContactEmail from ServiceProvider"

objRS.Open strSql, objConn

strSPMail = objRS("ContactEmail")

objRS.Close

strSubject = Trim(Request.Form("subject"))
strMessage = Trim(Request.Form("message"))

Set objMail = Server.CreateObject("CDONTS.NewMail")

objMail.From = strSPMail 'set mail sender address to that input by user
objMail.To = strCMail
objMail.Subject = strSubject 'set subject to subject input by user
objMail.Body = strMessage 'set message to that input by user

objMail.Send


When opening the page the following error message is displayed.

Server object, ASP 0177 (0x800401F3)
Invalid class string
/mailcustomer.asp, line 69


any help would be very useful

Cheers
 
I use the following to send email from ASP. You would need to set up an form post page to enter the data and then you could process it with this script. I have read that CDONTS does not work in newer releases of IIS.

Let me know if you need more code.

Cassidy
<%
'Standard settings for email
'Sample code used found@ '-----------------------------------------------------------------
Const cdoSendUsingMethod = "Const cdoSendUsingPort = 2
Const cdoSMTPServer = "Const cdoSMTPServerPort ="Const cdoSMTPConnectionTimeout = "Const cdoSMTPAuthenticate = "Const cdoBasic = 1
Const cdoSendUserName = "Const cdoSendPassword = "'------------------------------------------------------------------
dim cn
dim rs
dim m_objCDOcon
dim Fields
dim m_objCDO
dim sEmail

Set m_objCDO = Server.Createobject("CDO.Message")
Set m_objCDOcon = Server.Createobject("CDO.Configuration")
set cn = Server.Createobject("ADODB.Connection")
set rs = Server.Createobject("ADODB.Recordset")

sEmail = Request.form("Email")

if sEmail = "" then
Response.write "Please complete form"
else
'Replace with your database connection information
with cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "c:\inetpub\ .Open
end with

rs.Open "Select * from users where Email = '" & sEmail & "'",cn,1,3
rs.MoveFirst

'Sending email notification
set Fields = m_objCDOcon.Fields

'Setting up Message parameters
with Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
'Replace with your SMTP server
.Item(cdoSMTPServer) = "mail.yourserver.net"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
'Only used if SMTP server requires Authentication
'.Item(cdoSMTPAuthenticate) = cdoBasic
'.Item(cdoSendUserName) = "UserName"
'.Item(cdoSendPassword) = "Password"
.Update
end with

'Passing parameters to message object
Set m_objCDO.Configuration = m_objCDOcon

With m_objCDO
'Replace with email you wish the message to be sent to
.To = sEmail
'Replace with email you wish the message to be from
.From = "Do@Not.Respond.net"
'Replace with subject
.Subject = "Forgotten Password"
'Replace with information you want to be sent
.HTMLBody = rs("Password")
.Send
End With

Response.write "Email has been sent<BR>"
Response.write sEmail
end if


%>
 
Have tried using the code you kindly supplied but am now having a different error message displayed

(0x8004020F)
The event class for this subscription is in an invalid partition
/contactmail.asp, line 66


I have adapted your code in the following ways

'Standard settings for email
'Sample code used found@
'-----------------------------------------------------------------
Const cdoSendUsingMethod = "Const cdoSendUsingPort = 2
Const cdoSMTPServer = "Const cdoSMTPServerPort ="Const cdoSMTPConnectionTimeout = "Const cdoSMTPAuthenticate = "Const cdoBasic = 1
Const cdoSendUserName = "Const cdoSendPassword = "'------------------------------------------------------------------

dim subject
dim message
dim strConnection
dim m_objCDOcon
dim Fields
dim m_objCDO
dim sEmail

Set m_objCDO = Server.Createobject("CDO.Message")
Set m_objCDOcon = Server.Createobject("CDO.Configuration")

sEmail = Request.form("custEmail")
subject = Request.form("subject")
message = Request.form("message")


'Sending email notification
set Fields = m_objCDOcon.Fields

'Setting up Message parameters
with Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
'Replace with your SMTP server
.Item(cdoSMTPServer) = "timerecord"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
'Only used if SMTP server requires Authentication
'.Item(cdoSMTPAuthenticate) = cdoBasic
'.Item(cdoSendUserName) = "UserName"
'.Item(cdoSendPassword) = "Password"
.Update
end with

'Passing parameters to message object
Set m_objCDO.Configuration = m_objCDOcon

With m_objCDO
'Replace with email you wish the message to be sent to
.To = "smitha2@aston.ac.uk"
'Replace with email you wish the message to be from
.From = sEmail
'Replace with subject
.Subject = subject
'Replace with information you want to be sent
.HTMLBody = message
.Send
End With


Not quite sure on the settings for my smtp server

any further help would be gratefully recieved

Cheers
 
That seems strange for an SMTP server. Most SMTP servers require an A record in their dns point to mail.server.com or smtp.server.com. If you do not use an A record fot the SMTP server you need to have sometype of mail server like exchange locally on your network. In that case you would have to have a user name or password to make it work.

Please let me know which scenerio fits you and I will try to modify the code appropriatly.

Thanks

Cassidy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top