Receiving emails is the hard part; sending emails out to users is extremely easy. All you need to send emails is to use a SmtpClient
object and a MailMessage
object, both from the System.Net.Mail
namespace. Some of the methods in the previous section calls the SendEmail()
subroutine, which is defined as shown in Listing 6
If the Email parameter is empty, the code assumes that you want to send an email to all subscribed users; otherwise, it sends the email only to the email address specified in the Email parameter.
Finally, code the Send Message button as follows:
Testing the Application
'---sends a message to all subscribers---
Private Sub btnSendMessage_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
SendEmail(String.Empty, txtSubject.Text, txtMessage.Text)
Now that you have all the pieces together, let's put it to test. For this application, you have to ensure that Outlook is running before you run your application.
Send an email to the account that you use for the mailing list server with the subject "subscribe." After Outlook finishes downloading new emails, it notifies your application (via the NewMailEx event). The request will be queued and shown in the Queue Status ListBox (see left of Figure 6). About five seconds later, the request in the queue will be processed and your email address will be added to the list of subscribed users (see right of Figure 6).
At the same time, the application will automatically send a confirmation email to you, informing you that you have successfully subscribed to the list.
Figure 6. Subscribe: Subscribing a user to the mailing list.
Figure 7. Sending a Message: Sending a message to all subscribed users.
To unsubscribe from the mailing list, simply send an email with the subject "unsubscribe" to the same email account.
As the list administrator, to send an email to all subscribed users simply type in the subject and message and click the Send Message button (see Figure 7).
Basic and Useful
The most critical part of implementing a mailing list server is automating the subscribing and unsubscribing process. Of course, you can enhance it further by detecting bounced emails (such as emails account expiring when people change jobs), etc. Let me know if this application is useful to you.