Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 4th, 2004, 08:44 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: Halifax, Nova Scotia, Canada.
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP Email Newsletter help?

You guys are going to hate me real soon, lol

I have an asp page that sends a Newsletter to all the subsrcibers in the database. But we have been having trouble with it latley and my Hosting company told me I should send the newsletter in batchs of 50 instead of the whole list at one I have no idea how to do that here is my page, some things have been left out ;)

<%@ Language=VBScript %>

<%
    'on error resume next
    SQLStr="SELECT * FROM ORNewsletter"
    Set RS=Server.CreateObject("ADODB.Recordset")
    RS.Open SQLStr,Application("DBConn"),1,2,&H0001
    valuecount = 0

For y=1 to RS.RecordCount
    Dim HTML
    Set MailObj = CreateObject("CDONTS.NewMail")

    if RS("Format") = 1 then
        MailObj.BodyFormat=0
        MailObj.MailFormat=0
        HTML = "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">"
        HTML = HTML & "<html>"
        HTML = HTML & "<head>"
        HTML = HTML & "<link REL=""stylesheet"" HREF=""http://www.ourwebsite/oronline.css"">"
        HTML = HTML & "<title>WebSite Title</title>"
        HTML = HTML & "</head>"
        HTML = HTML & "<body bgcolor=""FFFFFF"">"
        HTML = HTML & "<p>"
        HTML = HTML & Request.Form("Body")
        HTML = HTML & "<br><br>_________________________________________ ____<br>This email was provided by <a href=""http://www.website"">Website</a><br>To unsubscribe from this newsletter at any time simply <a href=""http://www.Website/newsletter/unsubscribe.asp?Email=" & RS("Email") & "&RND=" & RS("RandomNumber") & """>click here</a><br><br>If this email is not formatted correctly <a href=""http://www.Website/newsletter/format.asp?Email=" & RS("Email") & "&Type=0"">click here</a> to receive text only emails."
        HTML = HTML & "</p>"
        HTML = HTML & "</body>"
        HTML = HTML & "</html>"
        MailObj.Body=HTML
    else
        MailObj.BodyFormat=1
        MailObj.MailFormat=0
        MailObj.Body=Request.Form("BodyText") & "To receive graphical emails click here:" & chr(13) & chr(10) & "http://www.Website/newsletter/format.asp?Email=" & RS("Email") & "&Type=1"
    end if
    ' The format of the message
    ' Set to 0 for HTML, 1 for plain text
    FromAddr="Website <email>"
    MailObj.From=FromAddr
    ' 0 = low
    ' 1 = normal
    ' 2 = high
    MailObj.Importance=1

    MailObj.Subject=Request.Form("Subject")

    MailObj.To=RS("Email")
    'MailObj.To="email"

    MailObj.Send
    Set MailObj = Nothing
    valuecount = valuecount + 1

    RS.MoveNext
next
Session("BodyofEmail") = null
Session("Emailstuff") = null
Session("Pressstuff") = null
Session("EventsEmail") = null
Session("PressEmail") = null
Session("NewsEmail") = null
%>
<html>
<head>
<title>Website | Newsletter Sent!</title>
</head>
<body>
<img src="/images/orlogowhite.jpg">
<br><br><table border=0 width=100% cellpadding=2 cellspacing=0>
    <tr>
        <td colspan=2 bgcolor="#021964">

            <b>The newsletter has been successfully submitted to <%=valuecount%> subscribers.
        </td>
    </tr>
    <tr>
        <td>

            <br>&nbsp;&bull;&nbsp;<a href="/default.asp">[u]Return to OR home</u></a>
        </td>
    </tr>
</table>
<%Session("Username") = null%>
</body>
</html>

-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason
__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
Reply With Quote
  #2 (permalink)  
Old June 4th, 2004, 09:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

"In batches of 50" how long can it wait before sending newsletters for the next 50?

Lets pool in some ideas on it before going for actually coding it.

I would say, you can have an additional column called MailSent (BIT type) so as to set its value as TRUE once the mail is sent. While selecting the records, you can
select TOP 50 COLUMNLIST from ORNewsletter where MailSent=0

And send mail for thos 50 recipients and for every mail sent, set its MailSent values as "1".

So at last when there are no records that are with MAILSENT=0, you can update them all back to "0" so as to enable you process the next NEWSLETTER for next day or so.

Also you can make this page auto-refresh after every 5 mins or so, depends on how long it takes to process first 50 records.

You may get some other better idea to go about. Good luck.

One last suggestion for you.
I would suggest you to use only FORMAT, RANDOMNUMBER and EMAIL in the select list, as I see you using only those three fields in processing this page.

Code:
SELECT FORMAT, RANDOMNUMBER, EMAIL FROM ORNewsletter
Cheers!

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #3 (permalink)  
Old June 4th, 2004, 09:27 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: Halifax, Nova Scotia, Canada.
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We send out the Newsletter at the end of everyday, after all the news comes in for that day. So if it send in batch's of 50 it would need to do it right in a row. I wasn't have a problem until this week. After I click send and it calls the handler.asp it times out after about 40 sec.
So I was told to send it in 50's instead of all 330 at once. Your idead sounds good, I can make a true/false column in the database.

-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason
Reply With Quote
  #4 (permalink)  
Old June 4th, 2004, 09:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I was also expecting Imar's feedback on this, Or if he has a better solution to this. ;)

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #5 (permalink)  
Old June 4th, 2004, 10:30 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I am not sure how mail servers handle this internally, but you could send the e-mail To yourself, and then BCC 50 addresses in each message. This way, your ASP application sets up a connection with the mail server only once for every 50 messages. Then the mail server will take care of distributing these messages to the final recipients.

Again, I am not sure how this is handled internally, so I may be talking crap here, but I think it will speed up things.... ;)

If you create a True/False column, don't forget to add a Date column or table somewhere as well. If you send out the e-mail daily, you need a means to reset the value to False for the next mail batch.

Do you have a means to schedule an application? These type of batch operations is usually not very suitable for an ASP page, and is usually handled better by a scheduled job....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #6 (permalink)  
Old June 4th, 2004, 10:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes you are right Imar.

If there is not content-wise change in the Newletter this can all done as you said. It should be faster, is what I too feel. But I assume that morpheus does something in the content that is personalised based on Email picked from the DB.

Quote:
quote:To unsubscribe from this newsletter at any time simply <a href=""http://www.Website/newsletter/unsubscribe.asp?Email=" & RS("Email") & "&RND=" & RS("RandomNumber") & """>click here</a>

To receive graphical emails click here:" & chr(13) & chr(10) & "http://www.Website/newsletter/format.asp?Email=" & RS("Email") & "&Type=1"
So I am not sure if that can be done using BCC with list of 50 email Ids.

Also I agree with you on doing this as a scheduled job as ASP is not the right one to do such things. May be writing VBScript and running it under scheduled task would be a point to think off.

Cheers!

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #7 (permalink)  
Old June 4th, 2004, 10:56 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You are absolutely right. I completely overlooked the personalized part of the message, so the BCC solution can't be used.

See, I told you I was talking crap..... ;)

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #8 (permalink)  
Old June 4th, 2004, 11:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

No Imar, there nothing crap in it, except the personalised content, your solution could be must faster really.

Just after reading your reply I did notice that.;)

Morpheus, should be waiting for more inputs though.

Cheers!

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #9 (permalink)  
Old June 4th, 2004, 11:08 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: Halifax, Nova Scotia, Canada.
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, The newsletter page grabs all of todays news and sends links to those articles, but only ones that are posted today, The newsleter is sent out at different times during the day because we never know when more news is going to come in. Imar I am not really sure what you mean about setting up a date column. I thought all I would have to do is.

Select top 50 from ORNewsletter where mailsent=0
Then send the email to the first 50 with mailsent=0

Then I would need a loop to say
For Every email sent set mailsent=1
next

Then just loop back to the top and go through again, this time skipping the ones that are Mailsent=1
until .eof

Then some how turn all mailsent=0 (not sure how to do this)

Okay that is really rough but if that's what you mean then I think I can do it

-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason
Reply With Quote
  #10 (permalink)  
Old June 4th, 2004, 11:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Select top 50 from ORNewsletter where mailsent=0
Quote:
quote:Then some how turn all mailsent=0 (not sure how to do this)
IF RS.EOF THEN
   Update Table set MailSent=0 'will be done all at one short.
   'At this point all records will have Mailsent=1 as you would have processed all rows by sending mails.
END IF

While not RS.EOF
   Send mail one by one.
   And store the mailId or KeyFieldValue in an array.
WEND

At one short using the values in Array, update the table for MAILSENT=1, as follows
'Update TABLE set Mailsent=1 where KEYFIELD in (Array_seperated_by_commas)
OR
'Update TABLE set Mailsent=1 where EMAILID in (Array_seperated_by_commas)


Hope that helps.
Sorry, I got to leave in a while from now, so I am just giving you the logic, may be you got to rearrange then in a way to work fine.
Dont mind.
Cheers!

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newsletter Mechanism vivek_inos ASP.NET 1.0 and 1.1 Professional 1 September 22nd, 2007 07:38 AM
Where is the newsletter option luisjeronimo BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 July 20th, 2007 03:16 PM
newsletter vantoko BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 February 28th, 2007 03:28 AM
Newsletter sydneyausguy BOOK: Professional DotNetNuke ASP.NET Portals ISBN: 0-7645-9563-6 1 August 19th, 2005 05:23 PM
help with newsletter question AStuntz Beginning PHP 1 May 13th, 2004 06:54 PM



All times are GMT -4. The time now is 12:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.