How do I use CDOSYS to send email

I'm new to ASP but am tasked with maintaining the company's intranet - written in ASP. One app I am working on today allows employees to register for HR training courses. Once they sign up, they are presented with a confirmation screen which currently only allows them to "print this page for your records." I would like to add an email confirmation to this app. I initially was going to use mailto but would rather do it on the server with CDOSYS. Problem - I don't know what I'm doing! Question: Below is the section of code executed when the employee has signed up for class. I'd like to insert a link to "Send email confirmation" that will contain the employee's email address, appropriate subject line, along with their specific course sign-up info in the body.  Your help is very much appreciated!

<%      '* * * Acknowledgement * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      If   (vAction = "PAU") Then
           vFrm_LName_fld = Request.Form("lname_fld")
           vFrm_FName_fld = Request.Form("fname_fld")
                     '---- Update Schedule Information ------------------------------------
           sql = "SELECT * FROM tblr_NEOSignUp_Sched WHERE id_Sched = " & vID_Sched_fld
            rsHR.open sql, HRConnection, adOpenForwardOnly, adLockOptimistic
           If   (rsHR("remainingseats") > 0) Then
                vSeatsLeft = 1
                rsHR("remainingseats") = rsHR("remainingseats") - 1
                rsHR.update
           Else
                vSeatsLeft = 0
           End If
                rsHR.close
      If   (vSeatsLeft = 0) Then
%>                  
           <div class="largeBox" style="padding-top:1.5em; padding-bottom:1em;">
           <div style="padding:.25em .25em .25em .25em; text-align:center; font-weight:bold; color:#ffffff; background-color:#ff0000;">Sorry, the course you have chosen has just closed.  Please select another from the <a href="signUp_NEOCourseList.asp">Course Listing</a></div>
           </div>
<%           Else
           vBGColor = "#ffffff"
           '---- Sign-Up Information --------------------------------------------
           rsHR.open "tblr_NEOSignUp", HRConnection, adOpenKeyset, adLockOptimistic, adCmdTable
           rsHR.AddNew
           rsHR("fname") = vFrm_FName_fld
           rsHR("lname") = vFrm_LName_fld
           rsHR("appt_id") = vID_Sched_fld
           rsHR("inputDte") = Now()
           rsHR("inputBy") = vAuthUser
           rsHR.update
           rsHR.close
%>
              <div class="largeBox" style="padding-top:1.5em; padding-bottom:1em;">
         <div style="padding:.25em; text-align:center; font-weight:bold; color:#ff0000; background-color:#FFFFCC;">Please print this page for your records.</div>

         '---- INSERT EMAIL CONFIRMATION HERE ??? ------------
            
         <p><img src="images/bullet_triangle_orange.gif">&nbsp;<a href="signUp_NEOCourseList.asp">Return to Course List</a></p>
         <p style="padding-top:.5em; padding-bottom:.5em; margin-bottom:0; border-top:1px solid #c3c6ff; border-bottom:1px solid #c3c6ff;">Thank you for signing up for New Employee Orientation on Cafe BEST!  Should you have any questions please contact Sandy Beach at <a href="mailto:sandy.beach@company.com?Subject=NEO Sign-up">sandy.beach@company.com</a> or 666-6666.</p>
         <table id="ConfirmData" border="0">
           <tr>
              <td class="label">Name:</td>
              <td class="data"><%= vFrm_LName_fld %>, <%= vFrm_FName_fld %></td>
         </tr>
         <tr>
              <td class="label">Course:</td>
              <td class="data"><%= vSched_Course %></td>
         </tr>
         <tr>
              <td class="label">Location:</td>
              <td class="data"><%= vSched_Loc %></td>
         </tr>
         <tr>
              <td class="label">Date:</td>
              <td class="data"><%= vSched_StartDte %></td>
         </tr>
         <tr>
              <td class="label">Time:</td>
              <td class="data"><%= vSched_StartTme %> - <%= vSched_EndTme %></td>
         </tr>
         </table>
         <div style="font-style:italic; padding-top:2em;">Submitted by <%= vAuthUser %> on <%= Now() %></div>
               </div>
               <% End If %>
      
LVL 1
OGSanAsked:
Who is Participating?
 
MGrassmanConnect With a Mentor Commented:
Below is the asp to send a email with cdonts

Set objSendMail = CreateObject("CDONTS.NewMail")
     objSendMail.From = strFrom
     objSendMail.To       = strTo
     objSendMail.Subject = strSubject
     objSendMail.Body = strBody
     objSendMail.Bcc = "email@companie.com;email2@companie.com"
     objSendMail.BodyFormat = 0    'Text Body Type  1 is used for HTML
     objSendMail.MailFormat = 1        'Text Mail Type
     objSendMail.Importance = 1    'Normal Priority, (0 = low) and (3 = high)
      
     objSendMail.Send
Set objSendMail = Nothing      
0
 
OGSanAuthor Commented:
Thanks, MGrassman - I recall reading other threads that recommended using CDOSYS moving forward, and refraining from using CDONTS.  Are there any changes to your answer above that would result if CDOSYS is used instead of CDONTS?
0
 
MGrassmanCommented:
Here's the code for CDOSYS also if you can use cdosys because newer servers may not by default use cdonts.

But here ya go.

<%
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Outgoing SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "you@yourdomain.com"
objCDOSYSMail.To = "recipient@theirdomain.com"
objCDOSYSMail.Subject = "This is my subject for my test message"
objCDOSYSMail.HTMLBody = "This is the body "
objCDOSYSMail.Send
"Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
OGSanAuthor Commented:
Thanks again - I'll take both and test each and report back by COB today.  Thanks, MGrassman.
0
 
OGSanAuthor Commented:
Clarification: I need to tie the email confirmation to either a button or link on the screen (see original question).  How do I do this?
0
 
OGSanAuthor Commented:
Yeehaw!  I am now sending email confirmation out!  But I still need to tie the function to a button or link - how do I do that?
0
 
brownmetalsConnect With a Mentor Commented:
Hi there.

You could have the page post back to itself when you or your user clicks the button. The form could put a string in the Querystring, and you can test for that string. If the string exists, you could execute the email CDOSYS code.

For example:

<%
If request.QueryString("sendEmail") = "yes" Then
     '------- Execute CDOSYS email here --------
End If
%>

<form name="emailForm" method="get" action="thisPage.asp?sendEmail=yes">
  <p>&nbsp;</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>

When you click the button, the form will put the URL + thisPage.asp?sendEmail=yes into the browser's address bar. Your If...Then statement checks to see if the sendEmail=yes. If so, it sends email. If not, the code does not execute. Doing it this way allows you to keep all your code on one page, without having to create a new page.

Hope that helps you out.
Good luck!
Jay
0
 
OGSanAuthor Commented:
Jay - Thanks for providing a solution consistent with the existing code.  You deserve at least half the points for taking time to suggest this.  Thanks to you, too, MGrassman.
0
 
brownmetalsCommented:
Hi there.

Thanks for the kind words, and the points. Continued good luck with your programming.

Jay
0
 
OGSanAuthor Commented:
Thanks, Jay, I'll need it!  "See you" again, I'm sure.
0
All Courses

From novice to tech pro — start learning today.