1. Products
  2.   Email
  3.   .NET
  4.   NetOffice
 
  

Free C# .NET Library for Reading & Writing Outlook Emails

Open Source C# .NET Library for Creating, Reading, Writing, & Manipulating Outlook Email Messages inside .NET Applications via C# API. 

What is NetOffice?

<

NetOffice is an open-source API that allows .NET developers to create Outlook email messages programmatically. Using the API, the developer can automate Microsoft Outlook, generate a document, modify it, and clean up resources. Furthermore, the API allows you to read the inbox folder, create task items, compose emails, send emails, add attachments to emails, receive emails, enumerate contacts and manage events.

One of NetOffice's standout features is its compatibility with various versions of Microsoft Outlook. Whether you're working with Outlook 2010, 2013, 2016, or beyond, NetOffice ensures a smooth experience, eliminating version-related headaches for developers.

In order to work with Outlook document, you need VBIDEApi.dll, with OfficeApi.ddl, and NetOffice.dll as dependencies and it allows you to create an application for 32-bit and 64-bit environment.

Previous Next

Getting Started with NetOffice

The easiest way to install NetOffice is via NuGet. To use it from Visual Studio’s Package Manager Console, please enter the following command.

install NetOffice via NuGet

 Install-Package NetOfficeFw.Email 

Install NetOffice via GitHub 

git clone --recursive https://github.com/NetOfficeFw/NetOffice.git 

Send Email via Free C# API

NetOffice allows .NET programmers to send Outlook emails programmatically. In order to send emails, first, you need to initialize an Outlook.Application After your Outlook application is started you can create a new mail item in it, set recipients, subject, and body. After you are done with the email message, you send your email. By using the following lines of code, you can send your emails easily.

Send Email Messages C#

  1. Start Outlook application by using Outlook.Application() method
  2. Create a new email item by using outlookApplication.CreateItem() method and set item type as olMailItem
  3. Add email recipients by using Recipients.Add() method and pass recipients as a string
  4. Set email subject
  5. Set email body
  6. Send email
  7. Quit and dispose of the outlook application

Send Emails Easily via Free C# APi

// start outlook
Outlook.Application outlookApplication = new Outlook.Application();

// create a new MailItem.
Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

// prepare item and send
mailItem.Recipients.Add("test@fileformat.com");
mailItem.Subject = "File Format Developer Guide";
mailItem.Body = "Send Emails programmatically in C#"
mailItem.Send();

// close outlook and dispose
outlookApplication.Quit();
outlookApplication.Dispose();

Retrieve Email Messages via C#

Retrieving emails from Outlook accounts is made efficient through the open source NetOffice's intuitive API. Software Developers can easily fetch emails based on various parameters such as date, sender, or subject, enabling them to implement powerful search and filtering functionalities. The library has included important functions for retrieving email messages, such as retrieve message asynchronously, retrieve message list, retrieve a specific message, retrieve to a file, and many more. Here is an example that shows how software developers can retrieve email messages inside C# .NET Applications.

How to Filters to Retrieve Specific Email Messages via .NET API?

// Filter emails from a specific sender
foreach (object item in inboxFolder.Items)
{
    if (item is MailItem mailItem && mailItem.SenderEmailAddress == "example@example.com")
    {
        // Process email...
    }
}

Manage Email Attachment

Managing email attachments is a crucial aspect of many applications. The free NetOffice .NET library makes it easy for software developers to handle email attachments inside their own .NET applications. The library excels in this area, allowing developers to seamlessly handle attachments, whether it's extracting them, adding new ones, or even modifying existing attachments with ease. The following example demonstrates how software developers can send email messages with atachments inside C# .NET Applications. The following example demonstrates how software developers can send email messages with attachments inside C# .NET Applications.

How to Add Attachments to Email Messages via .NET API?

using NetOffice.OutlookApi;
using NetOffice.OutlookApi.Enums;

class Program
{
    static void Main(string[] args)
    {
        // Create a new instance of Outlook Application
        Application outlookApp = new Application();

        // Create a new MailItem
        MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);

        // Set email properties
        mailItem.Subject = "Test Email";
        mailItem.Body = "This is a test email.";

        // Add attachment
        mailItem.Attachments.Add(@"C:\Attachments\example.pdf", Type.Missing, Type.Missing, Type.Missing);

        // Send email
        mailItem.Send();

        // Release COM objects
        outlookApp.Quit();
    }
}

 English