jassi123
New member
- Joined
- Oct 29, 2019
- Messages
- 2
- Programming Experience
- 1-3
Hello Team,
I have created a function to read email from outlook. Here is my code:-
However I am getting the following error message when I execute this code:-
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.
File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at EmailTrigger.Program.ReadMailItems()
at EmailTrigger.Program.Main(String[] args) in C:\Users\jaspreet1.singh\source\repos\EmailTrigger\EmailTrigger\Program.cs:line 12
Can someone please look into this issue.
Regards,
(Jaspreet Singh)
I have created a function to read email from outlook. Here is my code:-
C#:
using System;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Outlook;
using Microsoft.Office365.OutlookServices;
namespace EmailTrigger
{
class Program
{
static void Main(string[] args)
{
ReadMailItems();
}
private static void ReadMailItems()
{
Application outlookApplication = null;
NameSpace outlookNamespace = null;
MAPIFolder inboxFolder = null;
Items mailItems = null;
try
{
outlookApplication = new Application();
outlookNamespace = outlookApplication.GetNamespace("MAPI");
inboxFolder = outlookNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
mailItems = inboxFolder.Items;
foreach (MailItem item in mailItems)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("From: " + item.SenderEmailAddress);
stringBuilder.AppendLine("To: " + item.To);
stringBuilder.AppendLine("CC: " + item.CC);
stringBuilder.AppendLine("");
stringBuilder.AppendLine("Subject: " + item.Subject);
stringBuilder.AppendLine(item.Body);
Console.WriteLine(stringBuilder);
Marshal.ReleaseComObject(item);
}
}
catch (System.Exception ex) { throw ex; }
finally
{
ReleaseComObject(mailItems);
ReleaseComObject(inboxFolder);
ReleaseComObject(outlookNamespace);
ReleaseComObject(outlookApplication);
}
}
private static void ReleaseComObject(object obj)
{
if (obj != null)
{
Marshal.ReleaseComObject(obj);
obj = null;
}
}
}
}
However I am getting the following error message when I execute this code:-
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.
File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at EmailTrigger.Program.ReadMailItems()
at EmailTrigger.Program.Main(String[] args) in C:\Users\jaspreet1.singh\source\repos\EmailTrigger\EmailTrigger\Program.cs:line 12
Can someone please look into this issue.
Regards,
(Jaspreet Singh)
Last edited by a moderator: