p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   ASP Email Newsletter help? (http://p2p.wrox.com/showthread.php?t=13765)

morpheus June 4th, 2004 08:44 AM

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

happygv June 4th, 2004 09:17 AM

"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
[8]Strive for Perfection[8]

morpheus June 4th, 2004 09:27 AM

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

happygv June 4th, 2004 09:44 AM

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

_________________________
-Vijay G
[8]Strive for Perfection[8]

Imar June 4th, 2004 10:30 AM

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.

happygv June 4th, 2004 10:49 AM

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
[8]Strive for Perfection[8]

Imar June 4th, 2004 10:56 AM

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.

happygv June 4th, 2004 11:00 AM

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
[8]Strive for Perfection[8]

morpheus June 4th, 2004 11:08 AM

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

happygv June 4th, 2004 11:18 AM

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
[8]Strive for Perfection[8]


All times are GMT -4. The time now is 02:59 PM.

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