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

Sending mail through ASP 1

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
0
0
For some reason I can't seem to be able to send an e-mail through asp. I've got a contact page, which contains a form with an edit box and a multi-line edit. The edit is the persons e-mail address and the other is where they put the message. When they press send, it goes to a "message confirmed" page, (named contacted.asp.)
When there, it was supposed to send the message. It doesn't. Does anyone have any code on how to send an e-mail or anything? Cyprus
 
your code that you are working on would be the best way for us to come up with a solution as there are many components you may be using to process the email but here is a basic example with ASPMail

<%
Set Mailer = Server.CreateObject(&quot;SMTPsvg.Mailer&quot;)
Mailer.FromName = &quot;name of domain&quot;
Mailer.FromAddress = &quot;email@yourdomain.com&quot;
Mailer.RemoteHost = &quot;localhost&quot;
Mailer.AddRecipient &quot;name to recieve&quot;, &quot;email@to address.com&quot;
strMsgHeader = &quot;You had a form submitted&quot; & vbCrLf

For Each QueryString in Request.QueryString
strMsgInfo = strMsgInfo & qryItem & &quot; - &quot; & request.querystring(qryItem) & vbCrLf
Next
strMsgFooter = vbCrLf & &quot;End of request&quot;
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter
if Mailer.SendMail then
Response.Redirect &quot;contacted.asp&quot;
else
Response.Write &quot;Mail send failure. Error was &quot; & Mailer.Response
end if
%> ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Also make sure you have a default account set up with an email program or you have a default SMTP server listed in your IIS settings. Without this it doesn't know what to do with the message once you finish it and attempt to send it.
Note: I don't believe this is a problm with ASPMail or JMail, as you can specify the SMTP server in the object, but it is a problem with CDONTS.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Well here's my code.

<%
Set Mail = Server.CreateObject(&quot;Persits.MailSender&quot;)
Mail.Host = &quot;smtp.mysite.com&quot;
Mail.From = &quot;testing&quot;
Mail.FromName = &quot;your name&quot;

Mail.AddAddress &quot;myaddy@mysite.com&quot;
Mail.AddReplyTo &quot;youraddress@yourdomain.com&quot;
Mail.Subject = &quot;Test&quot;
Mail.Body = &quot;To whom it may concern:&quot; & Chr(13) & Chr(10) & _
&quot;This is a test.&quot;

On Error Resume Next
Mail.Send
If Err <> 0 Then
Response.Write &quot;Error encountered: &quot; & Err.Description
End If
%>

And when it sends I get a 501 Syntax error... I'll try your code and see if I can get it to work Cyprus
 
question
why are you doing this
Mail.Body = &quot;To whom it may concern:&quot; & Chr(13) & Chr(10) & _
&quot;This is a test.&quot;

aren't chr(13) and (10) the same result **

and why not just do
&quot;To whom it may concern:**This is a test.&quot; ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
I guess so, I just leached the code out of some how to thing. I changed it to the **. But even so, that's proprietary...

Whats a 501 syntax error and why am I getting it? Cyprus
 
basically just what it says. a syntax error
a ' in the wrong place etc etc etc

what line is the error pointing too?

do you know what components you have available to you. CDONTS ASPMail ASPEmail etc etc?

---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
You know you could also use CDO. You'll need the cdovbs.inc and then code is but a few lines.
For example:

<!-- #include file=&quot;../../../CDOVBS.INC&quot; -->

set objMail = Server.CreateObject(&quot;CDONTS.Newmail&quot;)
objMail.From = USER_ID & &quot;@TheCareGroup.com&quot;
objMail.To = UserName & &quot;@TheCareGroup.com&quot;
objMail.Subject = &quot;Time Sheet Approval&quot;
objMail.Body = &quot;Your time sheet for pay period &quot; & strWeek & &quot;-&quot; & strEWeek & &quot; has been approved.&quot;
objMail.Send
 
and so we add to the list of options available [lol] ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
alright, I tried your code from your first reply, onpnt, and I got this error:


Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/contacted.asp, line 18

Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at:

Help? Cyprus
 
that means ASPMail is not available.

Are you testing these on your machine via IIS or uploading to a server.
---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
then you need to find out what you have available to you to use. what components are installed? This information should be redily available at the hosting companies site and or in your information recieved when signing up ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Jeese guys. After some 43 threads that match the words &quot;Sending Email via ASP&quot; in this forum, hasn't ANYBODY made an FAQ to address the various ways to do this oft asked for task?

I've seen seperate notes with example code for:
SMTPsvg
Persits
aspmail
cdonts

Hasn't anyone pulled all this together with a simple example for each component, and a link for further docs on each?
 
Rather than complaining/criticizing, why not write one yourself? You could even use part of the example from:
faq333-113 to do so. I have over 50 pieces of sample script on my computer, nearly anytime I consider writing a FAQ it comes down to which one should I write and how much time do I have on my hands. ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
ditto to Tarwn

I have worked slightly on another tutorial with ASPMailer but again time is of course my enemy

---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Cyprus:

In your code, your &quot;FROM&quot; string is not a valid email address. Change it to a complete address and try that.

Also, concerning your error: what is line 18 of your asp file?
 
This is line 18...
Set Mailer = Server.CreateObject(&quot;SMTPsvg.Mailer&quot;)

I changed the from thing to a legitimate e-mail addy and got.... nothing Cyprus
 
The problem now is that this line of code controls which mail program you are using (ie persits, aspmail, etc.) Your initial code indicated you were using persits, but the code sample posted earlier for you as an example was for ASPMail (SMTPsvg.Mailer is the dll object for ASPMail).

Your system is telling you it can't create this object -- most likely because it does not have ASPMail installed.

As such, I recommend that you go back to creating the correct persits object, and enter a fully qualified email address. Simplify the BODY variable (get rid of the Chr's for now), also don't attempt any attachments at this time.

Persits details are available from including some code samples, and specifics on the methods and how to register its dll. Make sure you have it installed correctly on your web server -- or your code won't execute no matter what you try.

Keep trying!

Here is the basic sample they provide:

<%
Set Mail = Server.CreateObject(&quot;Persits.MailSender&quot;)
Mail.Host = &quot;smtp.smtp-server.com&quot; ' Specify a valid SMTP server
Mail.From = &quot;sales@veryhotcakes.com&quot; ' Specify sender's address
Mail.FromName = &quot;VeryHotCakes Sales&quot; ' Specify sender's name

Mail.AddAddress &quot;andy@andrewscompany.net&quot;, &quot;Andrew Johnson, Jr.&quot;
Mail.AddAddress &quot;paul@paulscompany.com&quot; ' Name is optional
Mail.AddReplyTo &quot;info@veryhotcakes.com&quot;
Mail.AddAttachment &quot;c:\images\cakes.gif&quot;

Mail.Subject = &quot;Thanks for ordering our hot cakes!&quot;
Mail.Body = &quot;Dear Sir:&quot; & Chr(13) & Chr(10) & _
&quot;Thank you for your business.&quot;

On Error Resume Next
Mail.Send
If Err <> 0 Then
Response.Write &quot;Error encountered: &quot; & Err.Description
End If
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top