Call a webpage recursively to send multiple emails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • john garvey
    New Member
    • Jan 2011
    • 50

    Call a webpage recursively to send multiple emails

    Hi

    It's been a while since I asked a question and I've trolled many, many discussion groups and forums without success and I'm not sure that my problem has a solution but here goes.

    I have a website which is hosted (successfully) on my own machine at home, it uses IIS7; classic ASP; activeX DLLs and an Access 2007 database. The website has an administration entrance where all the maintenance happens. I am transferring all the admin tasks from the Access DB to the Admin pages where most options are working OK.

    The website sends eMail to members once or twice a week using CDOSYS in the DLL, currently the Access DB form displays the progress showing the detail of who is currently being mailed, how many are remaining and a visual progress bar and When all mails are sent the form closes.

    I can reproduce the progress bar with CSS (although non moving at the moment) mail details etc and the code in the DLL to make it happen. The question is this:-

    How can I call the ASP page recursively before or after each mail has been sent. The DLL code I have will either send one or all emails, and if I send say 200 mails this leaves the webpage blank for three or four minutes until the DLL function returns, up until that point, I do not know what is happening.

    Any help would be appreciated.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    It sounds like you should be using Ajax for this task.
    Write a JavaScript array of email-strings into the page.
    Use Ajax to loop through this array and submit the email to asp page that is responsible for emailing...only loop when the Ajax request returns the response to the page....at that point you can also update your progress bar to indicate how far through the email list you are.

    -Frinny

    Comment

    • john garvey
      New Member
      • Jan 2011
      • 50

      #3
      Originally posted by Frinavale
      It sounds like you should be using Ajax for this task.
      Write a JavaScript array of email-strings into the page.
      Use Ajax to loop through this array and submit the email to asp page that is responsible for emailing...only loop when the Ajax request returns the response to the page....at that point you can also update your progress bar to indicate how far through the email list you are.

      -Frinny
      Thanks, however I've not used Ajax and it may take some time to learn. There may be another answer in the short term.

      Regards

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I can't really see this solution working well without using Ajax or JavaScript.

        How do you see it working without JavaScript?

        I mean, after completing one email, you'd have to send a response to the browser...at which time the browser would have to send up another request to send the next email. How is the browser going to send that next request without a client script??

        I don't think it will take as long as you think to learn how to do this with Ajax. It took me maybe a day to figure out....and there's a wonderful, friendly team of JavaScript experts here on bytes that would love to give you a hand :)

        -Frinny

        Comment

        • john garvey
          New Member
          • Jan 2011
          • 50

          #5
          This is the reason I've asked the question because I don't know how to do this bit.

          The eMails are actually personalised HTML invitations to our members which contain embedded graphics and a link holding user and visit information from the database which allows the invitee to enter the website and visit a dynamic page which contains information specific to that invitation. The DLL constructs and sends the eMail and not the webpage.

          As I stated previously I can send as many eMails as necessary but I need something on the screen to tell me that stuff is still happening. I thought of one of those spinning stars, but have been unable to locate one anywhere, when the mail session ends the DLL reports back to the web page the number of mails sent.

          Hope this sheds a little more light on the subject

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            It is a lot easier if you don't want a progress bar and you just want to display a graphic or message telling the user that the server is processing their request!

            You still need to use JavaScript for this but it's quite a bit more simple.

            Just add an element on the page that which will contain your image or message and set it's style of "display:no ne" so that it is not showing at first. Then add an "onclick" to your button that will call a JavaScript method that displays the element (when the user clicks the button). When the request returns from the server the element will be re-hidden because that is it's natural state.

            For example:
            Code:
            <html>
              <head>
                <script type="text/javascript">
                  function displayMessage()
                  {
                    document.getElementById("processingMessage").style.display="block";
                  }
                </script>
              </head>
              <body>
                
                <div id="processingMessage" style="border:solid 1px black;  position:fixed; display:none;background-color:red;">
                  Processing your request.
                </div>
            
                <button type="button" onclick="displayMessage()">Click Me</button>
              </body>
            </html>
            -Frinny

            Comment

            • john garvey
              New Member
              • Jan 2011
              • 50

              #7
              Thanks for this, however, I currently use a popup window with the message that eMail is being sent, when the server DLL has completed it returns the number of eMails sent, which is similar to your suggestion, the graphics are part of the HTML eMail not the webpage.

              What I am trying to do is continuously show the state of each eMail being sent, not have a big time gap with no user advice.

              Maybe I could have an array filled with the mail data and then send them individually to the DLL and wait the 1 second or so it takes to send and update the page that way.

              Kind regards

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                The thing is that you cannot have the "wait" happen in your server-side code. You have to have the "waiting" happen in your client side code...using JavaScript.

                You can't have the waiting happen in your server-side code because the response will never be sent to the browser and the browser's UI won't be updated.

                We're kind of returning to my original recommendation here...you don't need to use Ajax (Ajax just makes it smoother).

                Comment

                • john garvey
                  New Member
                  • Jan 2011
                  • 50

                  #9
                  I have not said the wait will happen on the server; here is a snippet of my code.

                  Visit is the entry point to the ActiveX DLL and its major class
                  reportmail is a class in the DLL sendReportMail is a public Function in reportmail which executes the confiuration and sending of eMail also returning the variant howMany containing the number of eMails sent. True and False indicate if a test eMail is sent to the operator for testing purposes.

                  The ASP code below calls the function and waits for the return of howmany. If howmany contains anything it is currently sent to a page to view.

                  Code:
                  Dim howMany
                  
                  If request("mailaction") = "sendmail" then
                    select case request("whichMail")
                      case 1
                        Visit.reportmail.sendReportMail True, howMany
                      case 2
                        Visit.reportmail.sendReportMail False, howMany, Request("clientid")
                      case 3
                        Visit.reportmail.sendReportMail False, howMany	 
                    end Select
                  	
                    if howMany <>"" then
                      Response.Buffer = True
                      Response.Clear
                      Response.Redirect "../admin/sniffer.asp?Sent=" & howMany
                    end If
                  End if
                  So the wait happens on the client until the server returns its answer.

                  I am more and more thinking this is not achievable i.e to see my counter going 1 of 250 sent.... 73 of 250 sent etc.

                  I may look at other ways.

                  Kind regards
                  Last edited by Frinavale; Oct 7 '11, 01:11 PM. Reason: Added code tags

                  Comment

                  • jimatqsi
                    Moderator Top Contributor
                    • Oct 2006
                    • 1290

                    #10
                    Why not just send a few emails at a time? Arrange a loop to call the email process for one email or a small group of emails and show the progress before each call? I don't know much about web apps - maybe it shows :)

                    Jim

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      I normally don't work with classic asp but here's an example of what I was talking about.

                      Code:
                      <html>
                      <head>
                        <title>test asp</title>
                      </head>
                      <body onload="startTimer()">
                        <form action="test.asp" method="post" id="testForm">
                       
                        <%
                          dim numLeft
                          numLeft=Request.Form("numLeft")
                          If numLeft<>"" Then
                      
                              numLeft = numLeft - 1
                      
                              dim percentComplete
                              percentComplete = (20-numLeft)/20*100
                      
                              Response.Write(percentComplete)
                              Response.Write("%")
                      
                              If numLeft<0 Then
                                numLeft=20
                              End If
                      
                          Else 
                            numLeft=20
                          End If
                        %>
                       
                          <input type="Hidden" name="numLeft" id="numLeft" value="<%=numLeft%>" />
                          <script type="text/javascript">
                            function submitPage()
                            { 
                              var numLeft = Number(document.getElementById("numLeft").value);
                             
                              if(numLeft>0)
                              {
                                document.getElementById("testForm").submit();
                              }       
                            }
                            function startTimer()
                            {
                               var t=setTimeout("submitPage()",1000);
                            }
                          </script>
                        </form>
                      </body>
                      </html>
                      Pretend the "numLeft" is actually the "number of emails left to send". This will change as the emails are sent...

                      -Frinny
                      Last edited by Frinavale; Oct 11 '11, 02:23 PM.

                      Comment

                      • john garvey
                        New Member
                        • Jan 2011
                        • 50

                        #12
                        Originally posted by jimatqsi
                        Why not just send a few emails at a time? Arrange a loop to call the email process for one email or a small group of emails and show the progress before each call? I don't know much about web apps - maybe it shows :)

                        Jim
                        Thanks Jim, however, when sending anything up to 600-700 mails I would spend all day clicking the go button. How would you 'arrange a loop' because basically that's what this is all about

                        Regards

                        Comment

                        • john garvey
                          New Member
                          • Jan 2011
                          • 50

                          #13
                          Originally posted by Frinavale
                          I normally don't work with classic asp but here's an example of what I was talking about.

                          Code:
                          <html>
                          <head>
                            <title>test asp</title>
                          </head>
                          <body onload="startTimer()">
                            <form action="test.asp" method="post" id="testForm">
                           
                            <%
                              dim numLeft
                              numLeft=Request.Form("numLeft")
                              If numLeft<>"" Then
                          
                                  numLeft = numLeft - 1
                          
                                  dim percentComplete
                                  percentComplete = (numLeft-20)/20*-100
                          
                                  Response.Write(percentComplete)
                                  Response.Write("%")
                          
                                  If numLeft<0 Then
                                    numLeft=20
                                  End If
                          
                              Else 
                                numLeft=20
                              End If
                            %>
                           
                              <input type="Hidden" name="numLeft" id="numLeft" value="<%=numLeft%>" />
                              <script type="text/javascript">
                                function submitPage()
                                { 
                                  var numLeft = Number(document.getElementById("numLeft").value);
                                 
                                  if(numLeft>0)
                                  {
                                    document.getElementById("testForm").submit();
                                  }       
                                }
                                function startTimer()
                                {
                                   var t=setTimeout("submitPage()",1000);
                                }
                              </script>
                            </form>
                          </body>
                          </html>
                          Pretend the "numLeft" is actually the "number of emails left to send". This will change as the emails are sent...

                          -Frinny
                          I could no get your script to run IE gave me a 'Object doesn't support this property or method

                          Kind regards

                          Comment

                          • Frinavale
                            Recognized Expert Expert
                            • Oct 2006
                            • 9749

                            #14
                            Umm I just tested it in IE8 and I don't get any problems...
                            Refresh the page, click the "line numbers" to turn off the line numbers for the code that I posted...copy the code that I posted and paste it into a file called "test.asp". ..

                            Comment

                            • john garvey
                              New Member
                              • Jan 2011
                              • 50

                              #15
                              When I copied the first time a line of text was deleted. Does work now in IE9.

                              Can this be made to call my DLL function ?

                              Comment

                              Working...