Keyvan Nayyeri

Musings of a Ph.D. student in Computer Science

Gopi 2.0 Released

Photo taken from http://c-sc.org/images/emailIcon.png Back in May 2006 I introduced an open source component which was called Gopi and was designed for sending emails via SMTP with .NET 2.0. The component could work with SQL Server as the storage system to keep all emails and make sure all emails are sent to recipients.

Gopi was written based on my own requirements at that time and could work very well for me in some projects. However, software world is growing very fast and some excellent ideas came out after the release that made me think of extending the component after almost two years.

So a few weeks ago I started a new open source project on CodePlex to move Gopi to it and licensed this component under an Apache 2.0 license. In this while I worked on the code to improve it and add some new features to the library and today I can announce the availability of version 2.0 of Gopi.

What's New?

This new version is rewritten from the base and only some parts of the code are brought to this version from version 1.0. Here is a list of changes and new features for version 2.0:

  • New storage system: As I described in a separate post, version 2.0 uses XML serialization for MailMessage class to store emails into the database and retrieve them. This enables a great way for extensibility in the future and makes things pretty simpler. This is the main addition to version 2.0 and brings lots of new stuff to the component such as support for attachments and other fields.
  • Data provider model: version 1.0 used a default SQL Server storage without the ability to use different storage systems but version 2.0 implements a provider model to let you implement your own data provider and use it. There is a built-in SQL data provider for you as well.
  • XML code comments: This new version also comes with XML code comments for better explanation and ease of use for end users.

However, the replacement of traditional multi-field storage system with new serialized data storage is the main new feature in this version and makes things simpler.

How to Use

After downloading the component and deploying the binary file to your server, you just need to touch your application configuration file to add the appropriate elements for data provider. Below code shows an example of the configuration that includes everything that you need to know to get started with the library.

<?xml version="1.0"?>

<configuration>

  <configSections>

    <section

      name="GopiProvider"

      type="Gopi.Provider.DataProviderConfiguration, Gopi"/>

  </configSections>

  <connectionStrings>

    <add

      name="ConnectionString"

      connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB.mdf;Integrated Security=True;User Instance=True"

      providerName="System.Data.SqlClient" />

  </connectionStrings>

 

  <GopiProvider default="SqlProvider">

    <providers>

      <add name="SqlProvider"

          type="Gopi.Provider.SqlDataProvider, Gopi"

          connectionString="ConnectionString"/>

    </providers>

  </GopiProvider>

</configuration>

There is a main Sender class in Gopi 2.0 that has several constructors and gets your SMTP server properties such as its address, username, password, port and timeout from them. This class provides a few methods to add your MailMessage objects to data storage and send a specified number of stored emails or all of them to recipients. This class is easy to use.

To add a new MailMessage object to data storage, you can use the AddNewEmail method as is shown in the below code.

protected void btnAddEmail_Click(object sender, EventArgs e)

{

    MailMessage email = new MailMessage();

    email.From = new MailAddress("noreply@nayyeri.net", "Test User");

 

    email.To.Add(new MailAddress("test@nayyeri.net", "Keyvan Nayyeri"));

 

    email.Subject = "Test Email";

    email.Body = "<p>This is a test email for Gopi 2.0!</p>";

 

    email.IsBodyHtml = true;

    email.Priority = MailPriority.High;

 

    email.Attachments.Add(new Attachment(Server.MapPath("~/Image.jpg")));

 

    Sender gopiSender = new Sender();

    gopiSender.AddNewEmail(email);

 

    lblResult.Text = "Email Added!";

}

After adding your emails to the storage system you can use different overloads of SendAllEmails method to send all the stored emails or just the specified number of them. You can write your own code to schedule this process or just call this method on a random basis.

protected void btnSendAll_Click(object sender, EventArgs e)

{

    Sender gopiSender = new Sender("mail.samplesite.com", "username@samplesite.com", "password");

    gopiSender.SendAllEmails();

    lblResult.Text = "Emails Sent!";

}

The internal mechanism ensures that none of the emails are missed. It removes an email from the storage only and only if it can make sure it has been sent successfully.

Download

You can download the source code and binary for Gopi 2.0 in separate packages from its CodePlex workspace.

3 Comments

Fahrenheit Marketing is your resource for Search Engine Optimization in Austin.


Behnam
Mar 07, 2008 9:18 AM
#

Tanx Keyvan

very nice and useful


Brian Chavez
Oct 20, 2008 4:36 PM
#

This is exactly what I was going to do, I'm glad I found this, and I'm going to try it out!

Also, I wanted to schedule emails to be sent at a cretin time, one way to do this would be to use Quartz.NET. Thanks!


Keyvan Nayyeri
Oct 20, 2008 10:20 PM
#

@Brian

You may also want to try our Abidar task scheduling system for ASP.NET:

nayyeri.net/.../abidar-1.0-beta

Leave a Comment





Ads Powered by Lake Quincy Media Network