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

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

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!!!
0
kingsfan76
Asked:
kingsfan76
  • 14
  • 7
  • 4
  • +3
1 Solution
 
fritz_the_blankCommented:
If you are using windows NT, you can use CDONTS, if windows 2000, CDO. In either case, third-party components including ASPEmail (free at www.Persits.com) and JMail are very good. Is this your server or are you using a hosting service?


Here are a few samples:
****************
CDO Complex
******************

<%
Const cdoSendUsingMethod        = _
      "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort          = 2
Const cdoSMTPServer             = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort         = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout  = _
      "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate       = _
      "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic                  = 1
Const cdoSendUserName           = _
      "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword           = _
      "http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig  ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields     ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
      .Item(cdoSendUsingMethod)       = cdoSendUsingPort
      .Item(cdoSMTPServer)            = "smtp_server_name"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = cdoBasic
      .Item(cdoSendUserName)          = "username"
      .Item(cdoSendPassword)          = "password"

      .Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
      .To       = "Display Name <email_address>"
      .From     = "Display Name <email_address>"
      .Subject  = "SMTP Relay Test"
      .TextBody = "SMTP Relay Test Sent @ " & Now()
      .Send
End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>




****************
CDO Simple
******************

<%
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
With objMail
      ' Set message attributes
      .To       =  "Gerald Shoates <gerald.shoates@thismail.com>"
      .From     = "Gerald Shoates <gerald.shoates@thismail.com>"
      .Subject  = "CDO Sample"
      .TextBody = "This is a test email using CDO"

      ' Attachment using known static physical path
      '.AddAttachment "c:\somepath\somefile.txt"
      
      .Send
End With

Set objMail = Nothing
%>


****************
CDONTS
****************
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Message Request</TITLE>
</HEAD>


<body>

<% Language = VBScript%>

<%
strFirstName = request.form("FirstName")
strEmailAddress = request.form("EmailAddress")

Response.Write("Thank you for your request, " & strFirstName & ".")
Response.Write("<p>Your message has been sent.")


dim objMail
set objMail = CreateObject("CDONTS.Newmail")
    objMail.From = You@YourAddress.com
    objMail.To = strEmailAddress  
    objMail.Subject = "Email Request"
    Msg = "This is the first line of your message" & Chr(10)
    Msg = Msg & "This is the second line of your message... and so forth"
    objMail.Body = Msg
    objMail.Send
    Set objMail = Nothing
%>


</BODY>
</HTML>

********************
JMail
********************

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<%
Set JMail = Server.CreateObject("JMail.SMTPMail")

' This is my local SMTP server
JMail.ServerAddress = "mail.yourdomain.com:25"

' This is me....
JMail.Sender = "myemail@mydomain.net"
JMail.Subject = "Here you go..."
    ' Get the recipients mailbox from a form (note the lack of a equal sign).
    JMail.AddRecipient strEmailAddress

    ' The body property is both read and write.
    ' If you want to append text to the body you can
    ' use JMail.Body = JMail.Body & "Hello world!"
    ' or you can use JMail.AppendText "Hello World!"
    ' which in many cases is easier to use.
    JMail.Body = "Here you go. Your request has been approved" &_
    "and the program is attached to this message"


    ' 1 - highest priority (Urgent)
    ' 3 - normal
    ' 5 - lowest

    JMail.Priority = 1

    JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")

    ' Must make sure that IUSR_???? has access to the following files.
    JMail.AppendBodyFromFile "e:\mail\standard_footer.txt"
    JMail.AddAttachment "e:\products\MyProduct.exe"

    ' Send it...
    JMail.Execute
    JMail.ClearRecipients();
set JMail=Nothing
%>

<P>&nbsp;</P>

</BODY>
</HTML>

****************
ASPEmail
****************


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

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

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

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


Fritz the Blank
0
 
fritz_the_blankCommented:
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
0
 
barryfandangoCommented:
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
%>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
barryfandangoCommented:
damn... took too long... : )
0
 
barryfandangoCommented:
although, kingsfan, you should find the metadata lines in my example more convenient than the constant declarations at the top of fritz' example.
0
 
kingsfan76Author Commented:
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?
0
 
fritz_the_blankCommented:
If you have SMTP running on that server, use the CDO.

FtB
0
 
kingsfan76Author Commented:
@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
0
 
fritz_the_blankCommented:
You might want to make sure that the CDO.dll is on your machine. Also, are you running SMTP services on that server?

FtB
0
 
kingsfan76Author Commented:
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.
0
 
fritz_the_blankCommented:
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
0
 
CCongdonCommented:
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
0
 
kingsfan76Author Commented:
@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.
0
 
fritz_the_blankCommented:
Sorry, wrong address (type)

www.persits.com

0
 
fritz_the_blankCommented:
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
0
 
fritz_the_blankCommented:
Sorry, it looks like they changed the address--here it is:

http://www.aspemail.com/


FtB
0
 
gladxmlCommented:
try to check out the link might help

http://www.4guysfromrolla.com/webtech/faq/Email/faq2.shtml
0
 
CCongdonCommented:
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.
0
 
fritz_the_blankCommented:
@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
0
 
kingsfan76Author Commented:
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)
0
 
fritz_the_blankCommented:
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
0
 
kingsfan76Author Commented:
@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  
0
 
fritz_the_blankCommented:
Fair enough!

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

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

FtB
0
 
apirniaCommented:
fritz_the_blank

Whats your point here?
0
 
apirniaCommented:
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.....
0
 
fritz_the_blankCommented:
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
0
 
fritz_the_blankCommented:
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
0
 
barryfandangoCommented:
hello unsubscribe button!
0
 
kingsfan76Author Commented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 14
  • 7
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now