Sending Emails Through Outlook using C# and VB.NET | ||||||
|
||||||
.web>
Source Code: SendingEmailsThroughOutlookCB.zip Introduction In this article I will give you an example of how to add an e-mail to your Microsoft Outlook outbox folder using C# and/or VB.net. This example also show how easy it is to call functions written in VB.net from C# The code consists of three classes: Form1.cs, CSharp.OutlookMail.cs, VBNET.OutlookMail.vb The first thing you need to do is to add a reference to "Microsoft Outlook 9.0 Object Library" Click on add Reference, select the COM tab and select "Microsoft Outlook 9.0 Object Library".
The Namespace object represents the messaging service provider. In order to get access to all Outlook folders and items we have to use the MAPI namespace.
Now that we have the MAPI namespace, we can log on using using: <mapinamespace>.Logon(object Profile, object Password, object ShowDialog, object NewSession)
We now choose which folder we want to work with. A MAPIFolder object represents a single Outlook folder. For example you could use: Calender: Outlook.OlDefaultFolders.olFolderCalendar For this example we choose the Outbox folder
The following function takes 3 string as parameters. These will be the values that we will add to the to, subject and the email body fields. We create a MailItem, and set the To, Subject, and Body fields.
Conclusion: Microsoft .NET is extremely powerful and yet simple to work with. In this example, I showed how to add e-mail to Outlook outbox. In the next verion, I will add functions to add tasks, calender and contacts items. .web> |
http://www.c-sharpcorner.com//Internet/SendingEmailsThroughOutlookCB.asp