By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

Call a webpage recursively to send multiple emails

P: 50

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.
Oct 4 '11 #1
Share this Question
Share on Google+
17 Replies

Expert Mod 5K+
P: 9,731
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 that point you can also update your progress bar to indicate how far through the email list you are.

Oct 4 '11 #2

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

Oct 4 '11 #3

Expert Mod 5K+
P: 9,731
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 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 :)

Oct 4 '11 #4

P: 50
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
Oct 5 '11 #5

Expert Mod 5K+
P: 9,731
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:none" 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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <script type="text/javascript">
  4.       function displayMessage()
  5.       {
  6.         document.getElementById("processingMessage").style.display="block";
  7.       }
  8.     </script>
  9.   </head>
  10.   <body>
  12.     <div id="processingMessage" style="border:solid 1px black;  position:fixed; display:none;background-color:red;">
  13.       Processing your request.
  14.     </div>
  16.     <button type="button" onclick="displayMessage()">Click Me</button>
  17.   </body>
  18. </html>
Oct 5 '11 #6

P: 50
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
Oct 6 '11 #7

Expert Mod 5K+
P: 9,731
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 don't need to use Ajax (Ajax just makes it smoother).
Oct 6 '11 #8

P: 50
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.

Expand|Select|Wrap|Line Numbers
  1. Dim howMany
  3. If request("mailaction") = "sendmail" then
  4.   select case request("whichMail")
  5.     case 1
  6.       Visit.reportmail.sendReportMail True, howMany
  7.     case 2
  8.       Visit.reportmail.sendReportMail False, howMany, Request("clientid")
  9.     case 3
  10.       Visit.reportmail.sendReportMail False, howMany     
  11.   end Select
  13.   if howMany <>"" then
  14.     Response.Buffer = True
  15.     Response.Clear
  16.     Response.Redirect "../admin/sniffer.asp?Sent=" & howMany
  17.   end If
  18. 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
Oct 6 '11 #9

Expert 100+
P: 1,221
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 :)

Oct 7 '11 #10

Expert Mod 5K+
P: 9,731
I normally don't work with classic asp but here's an example of what I was talking about.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.   <title>test asp</title>
  4. </head>
  5. <body onload="startTimer()">
  6.   <form action="test.asp" method="post" id="testForm">
  8.   <%
  9.     dim numLeft
  10.     numLeft=Request.Form("numLeft")
  11.     If numLeft<>"" Then
  13.         numLeft = numLeft - 1
  15.         dim percentComplete
  16.         percentComplete = (20-numLeft)/20*100
  18.         Response.Write(percentComplete)
  19.         Response.Write("%")
  21.         If numLeft<0 Then
  22.           numLeft=20
  23.         End If
  25.     Else 
  26.       numLeft=20
  27.     End If
  28.   %>
  30.     <input type="Hidden" name="numLeft" id="numLeft" value="<%=numLeft%>" />
  31.     <script type="text/javascript">
  32.       function submitPage()
  33.       { 
  34.         var numLeft = Number(document.getElementById("numLeft").value);
  36.         if(numLeft>0)
  37.         {
  38.           document.getElementById("testForm").submit();
  39.         }       
  40.       }
  41.       function startTimer()
  42.       {
  43.          var t=setTimeout("submitPage()",1000);
  44.       }
  45.     </script>
  46.   </form>
  47. </body>
  48. </html>
Pretend the "numLeft" is actually the "number of emails left to send". This will change as the emails are sent...

Oct 7 '11 #11

P: 50
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

Oct 7 '11 #12

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

Kind regards
Oct 7 '11 #13

Expert Mod 5K+
P: 9,731
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"...
Oct 7 '11 #14

P: 50
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 ?
Oct 7 '11 #15

Expert Mod 5K+
P: 9,731
Do you see what I'm doing there?

I'm calling a JavaScript function every second which submits the page to the server if a counter (stored in a HiddenField) is greater than 0.

My server side code then subtracts one from a "counter" value, stores it in the HiddenField and returns to the browser....

Then the process starts over again.

There's no reason why you couldn't call your emailing functionality and store the number of emails still needing to be sent in the HiddenField...which the JavaScript method could check.

You could create a progress bar type thing using this concept.

It would be even smoother if you were to use Ajax ;) ;)

Oct 7 '11 #16

P: 50
Hi Frinny

Its been good coversing with you, but, over the weekend I was sending 400 mails and less than halfway through, the server rejected one of the addresses. My MS Access system gave me the error message and I was able to track the offending address and resend the balance. This gave rise to me thinking of handling exceptions, errors and large arrays of mail data. I said at the outset of this thread that what I wanted to do may not be achievable, I am now thinking that that may be the case and I shall use the Access setup for eMailing and the website for everything else.

Once again thanks for your input.

John C Garvey
Oct 10 '11 #17

Expert Mod 5K+
P: 9,731
John, I'm sorry that you were unable to solve your problem.

If you're emailing that much you should consider using an emailing list...If you're not using your own SMTP server, you're probably going to run into problems because your task will be considered as "spamming" and will likely be shut down.

Oct 11 '11 #18

Post your reply

Sign in to post your reply or Sign up for a free account.