In this chapter you've implemented a complete module for sending out newsletters to members who registered to receive them, either at initial registration time or later. The module sends out the e-mails from a background thread instead of the main thread used to process the page request, so that you don't risk page timeouts, and, above all, so that you don't leave the editor with a blank page that may last several minutes or more. To provide some feedback to the editor about the newsletter being sent, there's a second page that updates a progress bar and shows the updated status information every couple of seconds. Finally, end users can look at past newsletters listed in an archive page.
To implement all this, you've used advanced features such as multi-threaded programming, script call-backs, and the SmtpClient and MailMessage classes to compose and send e-mail messages. You've also seen other new features of ASP.NET such as asynchronous pages, which is a useful feature in many situations.
However, although this module works fine, there's always room for enhancements. Here are some suggestions for improvements you may wish to make:
Add the capability to send attachments with the newsletters. This can be very useful if you want to send HTML newsletters with images. Currently, you can only send e-mails with images, by referencing the full URL of the images on your server.
Add support for setting the priority of the newsletter e-mails.
Add the capability to have different mailing lists, for different topics, such as Parties, New Articles, or New Products in your store. This would require having more profile properties, and an expanded SendNewsletter page, so that you can choose the target mailing list.
The personalization placeholder's list may be further expanded — to include placeholders for the subscriber's location, for example. You may also build a parser that manages custom tags defined into the newsletter's body, and includes or excludes their content according to the user's profile. For example, the content of a section <profileProperty language="Italian">...</profile Property> could be included only in the newsletters for subscribers who choose Italian for the Language property in their profile. Or <profileProperty state="NY">...</profile Property> could be used to include content only for subscribers living in New York state. This mechanism would not be difficult to implement, and it would allow editors to create very targeted newsletters, something that is especially important for commercial and marketing purposes.
When the messages are sent out, you won't get an error or exception if the e-mail doesn't reach its destination because the e-mail address isn't valid. The SMTP server does its work without letting you know about the results. However, messages sent to non-existent addresses usually come back to the sender with an error message saying that the message couldn't be successfully delivered because the address does not exist. These error messages are sent to the server's postmaster and then forwarded to the site's administrator. At this point, when you get such a message, you can manually set that account's Newsletter profile property to none. However, a much better and automated approach would be to write a program (probably as a Windows service) that parses the incoming messages to find the error messages, automatically performing the unsubscribe operation.
In the last few chapters we've developed modules to strengthen the site-to-user communications, such as the polls module and this newsletter manager. In the next chapter you're going to implement a module to manage forums, which is an important form of user-to-user communication.