Solved

ASP Email - how to

Posted on 1998-12-15
20
183 Views
Last Modified: 2013-12-25
How do I send an email off of an asp form? I have a contact form that needs to be directly sent to a hardcoded email address. I am aware of the objnewmail method, but it isnt working and I would like another way to do this...
we have iis4, outlook express...etc on the nt server
Can someone supply a ready-to-go code?
0
Comment
Question by:jedimike
  • 7
  • 5
  • 5
  • +2
20 Comments
 
LVL 1

Expert Comment

by:rajgn
Comment Utility
You can use NewMail Object in the built in  library CDONTS(with IIS4.0) for mailing activities. It's very simple to use. You can build confirmation message based on the data the user enters(let's say 'mesg') then insert the following code to send it by mail.

Set objNewMail = CreateObject("CDONTS.NewMail")
objNewMail.Send("fromme@company.com", "toyou@company.com", "subject:Hello", _
                      mesg, 0) ' low importance
Set objNewMail = Nothing ' canNOT reuse it for another message

Use Bcc,Cc etc. properties of this object to send Bcc or Cc. For complete documentation of this object, refer to:

http://premium.microsoft.com/msdn/library/sdkdoc/iishelp/iis/htm/asp/amsmtp_0qzj.htm
0
 
LVL 1

Expert Comment

by:rajgn
Comment Utility
Assuming you didn't mean the above by 'objnewmail method'
0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
I got this example from you're other answer...It didnt work at all....code executes and no mail ever is sent...I used the EXACT same code as you wrote on the other guy's question....
Is there another way of doing this?
0
 
LVL 1

Expert Comment

by:rajgn
Comment Utility
Are you getting any errors? Can you post me the code you used in your case? Are you sure your're using IIS4.0(coz. IIS3.0 will not recognize this)? And check for the validity of the email ID's you used. I used the same in my case, never had any problems. Check for CDONTS in your server's registry. If that's also OK, you can think of third party controls. But I'm not sure how far they'll succeed(since component from Microsoft itself failed!). If you want to have info about other components, I can give you.
0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
Function SendMail(strFrom, strSendTo, strCC, strSubject, strBody)
   Dim objMail
   IF strSendTo <> "" then
      Set objMail = CreateObject("CDONTS.Newmail")
      objMail.From    = strFrom
      objMail.To       = strSendTo
      objMail.cc      = strCC
      objMail.Subject = strSubject
      objMail.Body    = strBody
      objMail.Send
      Set objMail = Nothing
   
      SendMail = TRUE
   ELSE
      SendMail = FALSE
   END IF
End Function

0
 
LVL 1

Expert Comment

by:rajgn
Comment Utility
sybe:

How you'r comments are different from my solution (except including the same code in a seperate function)?
0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
Here's my code.  This is the whole asp file with the exception of the code following the script

<%
'capture all of the data from the contact form
dim mailString
dim objNewMail

name=Request.QueryString("name")
address=Request.QueryString("address")
citystzip=Request.QueryString("citystzip")
phone=Request.QueryString("phone")
calltime=Request.QueryString("time")
email=Request.QueryString("email")
pname=Request.QueryString("pname")

paddress=Request.QueryString("paddress")
pcitystzip=Request.QueryString("pcitystzip")
pphone=Request.QueryString("pphone")
ptime=Request.QueryString("ptime")
pemail=Request.QueryString("pemail")

customer=Request.QueryString("customer")
vendor=Request.QueryString("vendor")
system=Request.QueryString("system")
upgrade=Request.QueryString("upgrade")

mailString = name & chr(10) & address & chr(10) & citystzip & chr(10)
mailString = mailString & phone & chr(10) & "The best time to call is :" & calltime & chr(10)
mailString = mailString & email & chr(10) & "My Pharmacy is : " & pname & chr(10)
mailString = mailString & paddress & chr(10) & pcitystzip & chr(10)
mailString = mailString & pphone & chr(10) & "The best time to call is :" & ptime & chr(10)
mailString = mailString & pemail & chr(10) & chr(10) & "Am I a current Mckesson Pharmacy Customer? " & customer & chr(10)
mailString = mailString & "My favorite software vendor is: "  & chr(10) & vendor & chr(10) & "How old is my system? " & system & chr(10)
mailString = mailString & "Do I plan on upgrading in the next 6 months?: " & chr(10) &  upgrade & chr(10)

'create the mail object
Set objNewMail = CreateObject("CDONTS.NewMail")  
objNewMail.from = "mmessagie@creabustech.com"
objNewMail.body = mailString
objNewMail.to = "mmessagie@creabustech.com"
objNewMail.subject ="Contact Information"
objNewMail.Send
Set objNewMail = Nothing 'canNOT reuse it for another message

'debugging statement
Response.Write "this was mailed"
%>
0
 
LVL 1

Expert Comment

by:rajgn
Comment Utility
I don't see any thing wrong with your code. Did you check the other possibilities I mentioned?
0
 
LVL 6

Expert Comment

by:PBall
Comment Utility
Make sure you have SMTP server installed when installing Option Pack 4.0.

And you need to configure the SMTP server to forward the email coming to it to the actual SMTP server (email gateway) for your company.  You can do so from Internet Service Manager.

If you don't have the correct setting (whether SMTP is not installed or no forwarding is set up) the code above will not function at all.  All you are going to have are a bunch of bad emails in the /mailroot/badmail directory of your web server (not sure where you put that thing also, but check there).


0
 
LVL 6

Expert Comment

by:PBall
Comment Utility
If you don't have the SMTP installed or don't know how to do it, another option is to use 3rd party email component such as JMail from Dimac (www.dimac.se).  It's free.

You still need to have a forwarding SMTP server to use to actually send the email across the net.  But with JMail and ASPMail, this option can be done programmatically.

something like:

objMail.SMTPserver = "163.111.20.10"

or something like that.

Again, you need to know your actual SMTP server address for it to work.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:PBall
Comment Utility
On IIS SMTP problem,
to set up the smart host (where to forward outgoing mail to),
launch ISM
Open SMTP property page
Tab over to delivery
and enter the IP address in the smart host field.

If you are using Exchange, you might try putting the IP address of the machine where the Exchange is into this field.

I think that's the only info that IIS SMTP need to work correctly.

You might want to check the mailroot/badmail directory also to see if the SMTP server are accepting your test emails that are sent thru CDO/NTS object.

Actually, check all directory under the mailroot directory (I dunno where you have that directory, go search on it, should be there).
0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
well we dont have the default smtp server running. We have it stopped because when we have it running we it screws up the exchange server5.5...Is there any setting in either to get smtp server and exchange server to work together?

0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
well we dont have the default smtp server running. We have it stopped because when we have it running we it screws up the exchange server5.5...Is there any setting in either to get smtp server and exchange server to work together?

0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
well we dont have the default smtp server running. We have it stopped because when we have it running we it screws up the exchange server5.5...Is there any setting in either to get smtp server and exchange server to work together?

0
 
LVL 10

Expert Comment

by:MasseyM
Comment Utility
I could not get CDO to work.. I use a component called JMail from www.dimac.net.  It is great!  Try it out.  It is also free and VERY simple to use and install.
0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
rajgn,

I posted the function as a comment, not because it is principally different from your solution, but because it is in a function, and I like to put things in functions.

I am sorry if that upset you.

0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
already know about this...i need to know why cdo doesnt work....I cannot "rig" my code to function correctly. If the server is setup wrong I need to know why...
0
 
LVL 6

Expert Comment

by:PBall
Comment Utility
Heh, I am not sure if you have solved your problem by now, but something just pop into my head.  Perhaps, if you change the port number for the IIS SMTP server to something else (other than port 25 which is the default SMTP port), you can have both SMTP server running at the same time....

0
 
LVL 2

Author Comment

by:jedimike
Comment Utility
I figured out that Microsoft lied....Exchange and SMTP do NOT work together on the same machine. I moved all of my sites to a new machine and route the outgoing SMTP to the machine with exchange and it works fine...They just dont work on the same machine.
Pball,,,answer this and you get the points
0
 
LVL 6

Accepted Solution

by:
PBall earned 100 total points
Comment Utility
Claiming point i supposed :)
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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

763 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

8 Experts available now in Live!

Get 1:1 Help Now