SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sending HTML Newsletters in a Batch Using SQL Server


Sending HTML Newsletters in a Batch Using SQL Server

Author
Message
Rob Fisk
Rob Fisk
SSC-Addicted
SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)

Group: General Forum Members
Points: 435 Visits: 428
Mike-1076638 (5/27/2010)
select * from subscribers where subscription_date=getdate()-365

Easy Peasy

Mike
DB Software Laboratory
ETL Tools for everybody


Well, that was my point with the purely fixed distribution list on the mailserver. I was explaining where this kind of solution is highly useful.

_______________________________________________________
Change is inevitable... Except from a vending machine.

Gift Peddie
Gift Peddie
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17690 Visits: 14456
This then runs at a particular interval as a scheduled task and I keep our Exchange Admin from breathing down my neck.


This relates to what I was saying about Enterprise restrictions these Exchange admins have created business for Google because Google let us run Asp.net System.NET code when Enterprise Exchange Admins and Hotmail were blocking our code. Today Google GMail pro is used by many small businesses. Microsoft is fighting back Exchange online Admins are Microsoft employees.

Kind regards,
Gift Peddie
Rob Fisk
Rob Fisk
SSC-Addicted
SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)SSC-Addicted (435 reputation)

Group: General Forum Members
Points: 435 Visits: 428
Gift Peddie (5/27/2010)
This then runs at a particular interval as a scheduled task and I keep our Exchange Admin from breathing down my neck.


This relates to what I was saying about Enterprise restrictions these Exchange admins have created business for Google because Google let us run Asp.net System.NET code when Enterprise Exchange Admins and Hotmail were blocking our code. Today Google GMail pro is used by many small businesses. Microsoft is fighting back Exchange online Admins are Microsoft employees.


I dunno, I can run any code I want. If I was to take my perfectly acceptable sql solution, export the already generated email list to another application/server to sort out and then manage the interim code, I sure as hell would want it in house rather than rely on 3rd party.

OK, google lets you run ASP code. So, your SQL job that is already run via SQL to generate other info, rather than using built in SQL Server mail functionality will what? Generate a temp table of recipients in time for a separate sheduled ASP task to read the table and communicate with google to create a sender list to send a mail?

Technically speaking I can actually create a temporary mailing group in exchange directly from SQL server but why would I want to.

"Also, on the exchange admin breathing down my neck" issue, that is only going to be a problem with small businesses who can't afford <exagerate>16 processor, quad core 64GB Exchange servers and TB leased lines</exagerate>. I know for a fact that paying for hardware, OS and Software it is a hell of a lot cheaper for us to do it in house with MS Exchange even over 2 years than it is to go corporate hosted.

Again though, that is off topic for this post. If you are sending a lot of emails via SQL Server, and the mail server balks a bit here is one suggestion as to how to batch it.

I also submitted an alternative batching solution. It may bo good, it may not be.

It would be nice to see more comments on the actual area of toppic (how to batch it)

I have not yet had a chance to do tests on the code for performance and look at it as a whole but intend to. I submitted my version as an alternative but it may be awful in comparison. It certainly has the flaw that the batch size is limited by an unknown amount depending on average email length in batch.

It's a good article, Let's discuss the article rather than the mirriad ways of sending email.

_______________________________________________________
Change is inevitable... Except from a vending machine.

Gift Peddie
Gift Peddie
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17690 Visits: 14456
but what if it is user subscription, that chan change minute to minute, that generates the recipient list so each new user has the email address as part of the user table in sql. What if also you need a query to pick the recipients, for instance all who have signed up for over a year, ot any criteria you want.

You can have a job to check if any citeria match then generate the emails based on matching criteria all within a single SQL job without having to pass the recipient list out to another process.

Keeping it within SQL server then reduces the number of platforms that need to be maintained.


I did not say the article is not a good article but I am saying DB mail comes with paid SQL Server editions but .NET code runs in all editions. And yes all subscriptions can be automated using SQL Server Express and Windows scheduler as needed.

Kind regards,
Gift Peddie
Paul Thornett
Paul Thornett
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 96
select ...
union
select ...
union
select ...
union
select ...

This is a ridiculous construct! If you are certain you do want to use union because you want to sort and deduplicate the rows, then you should always use this construct instead:
select ...
union all
select ...
union all
select ...
union
select ...



Mike Chamberlain
Mike Chamberlain
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 38
This article tells you "how", but my question would be "why?". Why would you even want to do this?

This is a horrendous solution. It is a sequence of ugly hacks, and almost every step of the article has something that makes me cringe.

SQL Server is a database engine, not some general purpose application programming environment. Use the database to store and manipulate data. Leave the higher level stuff like constructing HTML documents and sending emails to a general purpose programming language like C#.

People who are commenting that this is a beautiful solution do not know the meaning of beauty.
Satnam Singh
Satnam Singh
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1030 Visits: 1084
Mike,

In my case, the table storing the email addresses of the users to whom the Newsletters were supposed to be sent was in MYSQL database.It is also not possible that the organisations will be creating a seperate relay server for sending Newsletters.It is also possible that the organisation might be using the same relay server for this purpose as well as for the corporates internal use. If yes, then sending all the Newsletters in a bulk sometimes creates a heavy load.

Satnam
Mike Chamberlain
Mike Chamberlain
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 38
My question as to "why" is not "why would you want to send in batches" (the case for this is obvious, and you made it well), but "why would you want to do it all *in SQL Server*". My criticism is of the architecture, not the idea. Use the DB for data operations. Use an application for higher level operations. Don't force it all into the DB. Just because you can do it in SQL Server, doesn't mean that you should.

I understand that on some occasions it is sometimes necessary to hack together something that works, but is not necessarily beautiful, and I am as guilty as anyone of this. The difference is, I wouldn't write an article and post it on the internet telling everyone about it.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221016 Visits: 42002
Good article but I guess I'm missing something. Instead of sending things in batches of "x" quantity every 10 minutes, wouldn't it just be easier to send 1 email every 3 or 4 seconds?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Simon G
Simon G
SSC Veteran
SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)

Group: General Forum Members
Points: 259 Visits: 145
Good solution. We have used a very similar method for a while to send out large mailing lists on a daily basis. It's very quick.
Also, we send out in the thousands via an Agent Job, 1 at a time with a slight pause in between and don't get any issues.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search