Je suis en train de développer une application qui envoie des e-mails automatisés via les services Outlook et Interop et obtient l'exception suivante. ci-dessous est le code avec exception.Création d'un service Windows pour l'envoi d'e-mails automatisés via outlook com interop
try
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "Details of Subject";
mailItem.To = "[email protected]";
mailItem.Body = "Automated email testing"
// mailItem.Attachments.Add(logPath);//logPath is a string holding path to the log.txt file
mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
mailItem.Display(false);
mailItem.Send();
}
catch (Exception ex)
{
WriteErrorLog("\n");
WriteErrorLog(ex.Message);
WriteErrorLog(ex.StackTrace);
}
Et son lancer une exception:
System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType) at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType) at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at WServiceMixInOne.ConnectionLogs.MainClass() in C:\Users\admin\documents\visual studio 2017\Projects\WServiceMixInOne\WServiceMixInOne\ConnectionLogs.cs:line 120
Ligne 120 est la 1ère ligne app = new Microsoft.Office.Interop.Outlook.Application();
Juste pour être sûr. La perspective est-elle installée sur la machine et a-t-elle été démarrée au moins une fois? –
Quel est le type de l'exception lancée? – mjwills
Oui, Outlook installé et configuré, fonctionne bien pour les mails normaux. Les exceptions sont runtime, activator. Ai-je besoin de créer une instance de outlook pour y accéder? – NoobOwl