Solved

How do I use CDOSYS to send email

Posted on 2004-10-26
560 Views
Last Modified: 2012-06-27
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 %>
      
0
Question by:OGSan
    10 Comments
     
    LVL 2

    Accepted Solution

    by:
    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
     
    LVL 1

    Author Comment

    by:OGSan
    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
     
    LVL 2

    Expert Comment

    by:MGrassman
    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
     
    LVL 1

    Author Comment

    by:OGSan
    Thanks again - I'll take both and test each and report back by COB today.  Thanks, MGrassman.
    0
     
    LVL 1

    Author Comment

    by:OGSan
    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
     
    LVL 1

    Author Comment

    by:OGSan
    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
     
    LVL 4

    Assisted Solution

    by:brownmetals
    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
     
    LVL 1

    Author Comment

    by:OGSan
    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
     
    LVL 4

    Expert Comment

    by:brownmetals
    Hi there.

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

    Jay
    0
     
    LVL 1

    Author Comment

    by:OGSan
    Thanks, Jay, I'll need it!  "See you" again, I'm sure.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    846 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

    9 Experts available now in Live!

    Get 1:1 Help Now