Sending message with Outlook

Jul 28, 2013 at 6:27 AM
I'm new at this but trying to learn.

I've tried to write an standalone program to send an email through Outlook. The program will not compile though I'm using the example given in the documentation. I get 13 errors of the following types:

Error 1 Interop type 'NetOffice.OutlookApi.Application' cannot be embedded. Use the applicable interface instead.
Error 2 The type 'NetOffice.OutlookApi.Application' has no constructors defined
Error 3 Interop type 'NetOffice.OutlookApi.Application' cannot be embedded. Use the applicable interface instead.
Error 4 Interop type 'NetOffice.OutlookApi.MailItem' cannot be embedded. Use the applicable interface instead.
Error 5 'NetOffice.OutlookApi.Application' does not contain a definition for 'CreateItem' and no extension method 'CreateItem' accepting a first argument of type 'NetOffice.OutlookApi.Application' could be found (are you missing a using directive or an assembly reference?)
Error 6 Interop type 'NetOffice.OutlookApi.MailItem' cannot be embedded. Use the applicable interface instead.
Error 7 'NetOffice.OutlookApi.MailItem' does not contain a definition for 'Recipients' and no extension method 'Recipients' accepting a first argument of type 'NetOffice.OutlookApi.MailItem' could be found (are you missing a using directive or an assembly reference?)




What am I doing wrong?

The following is the complete code for the standalone program. I use VS2012.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OfficeApi;
using NetOffice;
using NetOffice.OutlookApi.Enums;
using Outlook = NetOffice.OutlookApi;

namespace NetOfficeOutlook
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        // 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("user@gmail.com");
        mailItem.ReplyRecipients.Add("otheruser@gmail.com");
        mailItem.Subject = "Test";
        mailItem.Body = "Test";
        mailItem.Send();

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

    }
}
}
Coordinator
Jul 28, 2013 at 6:50 AM
hello,

go to the references and set the option 'embedd interop types' to false for all NetOffice assemblies.

*Sebastian
Jul 29, 2013 at 10:09 AM
Thanks. No issues now.