Link to home
Start Free TrialLog in
Avatar of kingsfan76
kingsfan76

asked on

send email notification in ASP

hi, experts:

i haven't written any codes in ASP to send emails, but i'll need that soon.  Does ASP have built-in function to send email?  If so can someone give me a very simple but complete script to send an email with subject = "Notification" and message body with the following message:

Hello world!

From Mars

just use any dummy email address will be fine.  Thanks!!!
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America 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
As you can tell by the varying styles, I did not write all of these, but the question gets asked enough that I thought I would cobble a few examples together.

FtB
Avatar of barryfandango
barryfandango

this code will do what you ask.  It uses a windows 2000 (and later) package called CDOSYS.  If you're using pre-windows 2000 you have to use a slightly different package called CDONTS.




<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
<%
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iBp
Dim Flds

Dim iConf
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod)  = cdoSendUsingPort
Flds(cdoSMTPServer)       = "smtp.MyMailServer.com"
Flds(cdoSMTPServerPort)   = 25
Flds(cdoSMTPAuthenticate)     = cdoAnonymous
Flds.Update

With iMsg
  Set .Configuration = iConf
    .To          = "me@mydomain.com"
    .From        = "me@mydomain.com"
    .Subject     = "Notification"
    .TextBody    = "Hello world!" & vbCrLf & vbCrLf & "From Mars"

    .Send
End With
%>
damn... took too long... : )
although, kingsfan, you should find the metadata lines in my example more convenient than the constant declarations at the top of fritz' example.
Avatar of kingsfan76

ASKER

thanks for the quick responses.

@FtB and barryfandango:

i am using Windows 2000 Server with IIS 5.0
which one would you suggest me to use?  and do I need to download or install any components?
If you have SMTP running on that server, use the CDO.

FtB
@FtB:
I tested your code for the *CDO Simple* and it gives me the following error:

CDO.Message.1 error '80070005'

Access is denied.


it occur on the .send line.
I copy your code exactly for that part, and use my own email address.  am i missing something?

anyway i'm going to test the *complex* and the other codes right now
You might want to make sure that the CDO.dll is on your machine. Also, are you running SMTP services on that server?

FtB
SMTP server is on a different machine.  I guess i'll need to make sure CDO.dll is on the application server and get the mail server name and port no. first.
I'll get back a little later.  meanwhile i'll increase the points as well.
If you are using a remote smtp server, the ASPeMail available for free at www.persitis.com is really easy to set up and use. I have had great luck with it.

Fritz the Blank
Yeah, I found that out the hard way, if you're going to use CDONTS, you have to make sure that IIS's SMTP server is installed.

Here's a link to the MSDN page that explains the methods that can be used in this object:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_denali_newmail_object_cdonts_library_.asp
@CCongdon and @FtB:

I tried CDONTS and it gave me the permission denied error.  So if my SMTP server is on a different server from my application server, then I can't use CDO or CDONTS?  (I have no control over the servers)

@FtB:
I'll probably give ASPeMail a shot since it's free.  but the link is not working.
Sorry, wrong address (type)

www.persits.com

CDONTS cannot work with remote SMTP services.

CDO can, but the configuration can be tricky.

AspEmail works like a charm but lacks some of the functionality in terms of catching bad mail and etc.

FtB
Sorry, it looks like they changed the address--here it is:

http://www.aspemail.com/


FtB
Are you saying that you have no access at all to installing programs on the server? Because in that case, ASP E-Mail still won't work since you have to register the DLL.

Another possiblity, but it's VERY cludgy and out of date is to use a CGI script. There's a couple out there that do e-mail.

Or... you could use Front Page if your server supports Front Page extensions... Form to e-mail is a behavior natively supported by FrontPage. But as far as I know, it's only for packing up a form and e-mailing it.
@Glad--

Look further up the thread--that was already covered.

@CCongdon--

I am not sure whether kingsfan can use a third-party component. If not, then we will have to futz with CDO.

FtB
I can't install anything on the server, but i can ask and it should be no problem.  but having SMTP server on the server i'm currently working on is out of the question.

i think the free version of ASPmail should be enough for me as I only need to send a notification mail with a subject line and a very simple body message.  

thanks for all the replies.  It'll be probably be a day or two for me to test it out and PAQ this question.

diehard Kingsfan   :-)        (that's NBA Sac Kings)
I have used ASPeMail in a number of applications that require the use of remote SMTP servers with very good luck. There is only one downside: the free version doesn't queue up all of your mail in the event that the smtp server does not respond. CDO, and the Professional version of ASPeMail will queue up all of those messages and then send them when the service comes back on line.

What I have done is to write a little routine that captures any mail that didn't get sent and stores the pertinent data into a table so that the messages could be resent later. If you are interested, I can show you what I did for that.

FtB
@FtB:

thanks for the suggestion.  but with the current project schedule i probably don't have time to implement that.  i need something as simple as possible.  but i'll keep that in mind in the future (maybe a future expert question).  

just talked to system admin and he said if he set up a virtual SMTP server in IIS then i'll be able to use CDO/CDONTS, but problem is when we upload the app to the client's server it's not going to work.  so i guess i'll stick with ASPmail

kingsfan  
Fair enough!

FtB
here is a good one: go to www.aspemail.com
Version 4 is free.
@apirnia:

Please look further up the thread--that has been suggested already.

FtB
fritz_the_blank

Whats your point here?
Personaly I think if more than one person suggest the same thing, it means that it must be a working soloution.......and  maybe I should give it a try first.....
That it is not particularly constructive to repeat what has already been posted in the thread: the idea of using ASPeMail has already been proposed along with sample code and the URL where the code can be downloaded.

FtB
Oh, I see what you mean. Ordinarily, then, one would say something like "I agree that using ASPeMail is a good approach" or something like that.

FtB
hello unsubscribe button!
sorry about the delays on this question.  currently I'm not able to test the ASPMail object in our project server.  I'll try to install it in my own server at home and give it a test, and hopefully i'll be able to close this question soon.

kingsfan