Я пытаюсь открыть шаблон электронного письма (.msg) для редактирования, но код продолжает «захватывать» после попытки открыть шаблон.
Я продолжаю получать эту ошибку
Исключение: «System.InvalidCastException» в Estimator.exe
Это код:
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 Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;
using System.Drawing.Text;
// Create emails
Outlook.Application outlookApp = InitializeOutlook();
string msgPath = @"C:\Users\andyk\OneDrive\Projects\Visual Studio\Estimator\files\Template.msg";
try
{
// Open template
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.Session.OpenSharedItem(msgPath);
mailItem.Display();
}
catch (Exception ex)
{
Console.WriteLine($"Error opening template: {ex.Message}");
}
finally
{
// Clean up COM objects
Marshal.ReleaseComObject(outlookApp);
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... template-c