June 2008 - Posts

Aggr from ASP.NET Blog: Creating an Outlook Message File with C#

Following's a post I made on my ASP.NET Weblog (http://weblogs.asp.net/darrensim/default.aspx)

I've been working with a government agency lately, and came to notice that the software system they're using dates back to the stone ages. Many a time, the head of department is required to send an email to other head of departments within the same organization, each with a similar content, yet with attachment of nominal roll of folks under each of the departments (PS: HR Stuff).

On every occasion that I observe, this poor balding guy has to create a template in outlook and copy it 20 times, adding the list of recipients to the individual MSG file and attaching the relevant set of excel/word document file for each of these departments.

Of course, as a software engineer, the first thing on the mind is definitely, "AUTOMATION"!

Microsoft Office Outlook does have an interop dll which specifically allows for this to be done, easily! Another altanative would definitely be making use of Visual Studio Tools for Office (VSTO).

To save you the trouble of looking for this DLL, i've attached a copy to this blogpost.

1. To begin, let's first create a C# Winforms Project in Visual Studio.

2. Next, let's add the reference to the interop DLL (attached on this blog post). You should see something like the following.

3. For the purpose of this tutorial, we'd create a simple windows form which takes in the mail receipient, subject, message and attachment fields. Once you're familiar with how the code (which we'd discuss later), you can work more magic around this (e.g. creating automation processes)

Note: The Importance ComboBox should have the following values "High","Normal" and 'Low".

4. Next step, is to wire up the code-behind for the Save Button. It's optional whether you want to register the Outlook Interop in the namespace or not. In this example, I do not so so, thus qualifying the full path in the code (below).

// Creates a new Outlook Application Instance
Outlook.Application objOutlook = new Outlook.Application();

// Creating a new Outlook Message from the Outlook Application Instance
Outlook.
MailItem mic = (Outlook.MailItem)(objOutlook.CreateItem(Outlook.OlItemType.olMailItem));

// Assigns the "TO", "CC" and "BCC" Fields
mic.To = toTextBox.Text;
mic.CC = ccTextBox.Text;
mic.BCC = bccTextBox.Text;

// Assigns the Subject Field
mic.Subject = subjectTextBox.Text;

// Switch the Importance ComboBox to identify the Mail Message Importance Level
switch
(importanceComboBox.SelectedItem.ToString())
{
        case "High":
                mic.Importance = Outlook.
OlImportance.olImportanceHigh;
                break;
        case "Normal":
                mic.Importance = Outlook.
OlImportance.olImportanceNormal;
                break;

        case "Low":
                mic.Importance = Outlook.
OlImportance.olImportanceLow;
                break;
}

// Define the Mail Message Body. In this example, you can add in HTML content to the mail message body
mic.HTMLBody = messageTextBox.Text;

// Adds Attachment to the Mail Message.
// Note: You could add more than one attachment to the mail message.
// All you need to do is to declare this relative to the number of attachments you have.
mic.Attachments.Add(attachmentOneTextBox.Text,Outlook.
OlAttachmentType.olByValue,1,"Attachment Name");

// Save the message to C:\demo.msg. Alternatively you can create a SaveFileDialog to
// allow users to choose where to save the file
mic.SaveAs(
@"C:\demo.msg", Outlook.OlSaveAsType.olMSG);

Easy isn't it? Besides creating mail messages, you can also create other outlook items such as task, calendar objects and more. More to come in the future posts. Do let me know your comments/views on this post.

 

Attachments:

 Tutorial in PDF Format (http://darrensim.com/files/folders/presentations/entry9679.aspx)

 Interop.Outlook (http://darrensim.com/files/folders/presentations/entry9680.aspx)

Speed Browser

The war of the browsers had been persisting for many years. First with the Netscape Era, and now the Internet Explorer Era.  Of course, not forgetting potential contenders such as Opera, Firefox and Safari!

I've been a big fan of Microsoft IE for quite some time now, and have noticed that as the number of addons and etc come into place, the application just begins to crawl. Which sometimes can be a really bad thing!

Apple's Safari Browser has been really good with the SPEED issue, with really fast rendering. Although still in its early stages (in my personal perception), it can certainly go far if it continues to provide users with such lightning speed.

But of course, there's also a fair amount of criticism with regards to this new kid on the block, particularly, with regards to security, such as the PWN 2 OWN Browser Exploit. However, if you are just using the browser for basic research and surfing which does not include credentials or private data, it could be a good alternative when speed is concerned.

But of course, I would still recommend the use of IE for bank transactions.

Following are some of the browsers with it's release history (http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Release_history)  

BrowserFirst public releaseFirst stable releaseLatest stable release version dateLatest testing release version date
DateVersionDateVersion
AmayaNovember 14,19960.9November 14,19960.910.0.1  (February 292008; 116 days ago)10.1-pre  (April 292008; 56 days ago)
AOL ExplorerJune, 20051.0July, 20051.11.5  (May 102006)none  (n/a)
Avant????11.6 Build 19  (June 162008)none  (n/a)
CaminoFebruary 1320020.1February 1420061.01.6.1  (May 202008)none  (n/a)
DilloDecember, 19990.0.0December, 19990.0.00.8.6  (April 262006)none  (n/a)
ELinksDecember, 2001?December, 2001?0.11.4rc1  (March 042008)none  (n/a)
EpiphanyDecember 22,20020.4September 820031.02.22.1.1  (April 72008; 78 days ago)none  (n/a)
FlockOctober 2420050.4.9November 220071.01.2.1  (May 302008; 25 days ago)2.0 b1  (June 162008; 8 days ago)
GaleonJune, 20000.6June, 20000.62.0.5  (February 102008; 135 days ago)none  (n/a)
iCabFebruary 171999Preview 1.0February 171999Preview 1.04.1.1  (May 32008)none  (n/a)
Internet ExplorerAugust, 19951.0August, 19951.07.0  (October 162006)8.0 Beta 1  (March 52008; 111 days ago)
Internet Explorer for MacJanuary 2319962.0bApril 2319962.05.2.3  (June 162003)none  (n/a)
K-MeleonNovember 26,20000.2November 26,20000.21.1.5  (April 82008)1.5b2  (May 292008)
KonquerorOctober, 2000?October, 2000?4.0.5  (June 42008; 20 days ago)none  (n/a)
LinksNovember 24,19990.8November 24,19990.82.0  (June 102002)2.1pre36  (May 132008)
LynxJuly, 1993?July, 1993?2.8.6  (October 112006)none  (n/a)
MaxthonJuly 1120020.1 (as MyIE2)September 820051.0.02502.0.7.1245  (December 282007)none  (n/a)
MosaicApril 2219931.0April 2219931.0Unix: 2.6; Mac OS, Windows: 3.0  (Mac OS, Unix: 1996; Windows:1997)none  (n/a)
MozillaDecember 71998"Preview"March 191999M31.7.13  (April 212006)none  (n/a)
Mozilla FirefoxSeptember 23,20020.1September 23,20020.13.0  (June 172008; 7 days ago)none  (n/a)