Sicos1977 / MsgKit

A .NET library to make MSG files without the need for Outlook
199 stars 55 forks source link

Start.Process throws an error. #92

Closed pharry22 closed 1 year ago

pharry22 commented 1 year ago

System.Diagnostics.Process.Start(@"c:\temp\email.msg");

Throws this error.

The file is created and if I double click on it from file manager it opens the email in outlook.

Is there something else I need to?

System.ComponentModel.Win32Exception: 'Failed to start a process with file path 'c:\temp\email.msg'. Target file or working directory doesn't exist, or the provided credentials are invalid.'

TIA

Sicos1977 commented 1 year ago

I guess the folder does not exists on your computer.

pharry22 commented 1 year ago

Hi, Thanks for your reply. The issue seems to be the runtime.

If I use the Framework 4.8 it works.

If I use .Net 6 or 7 I get this error. {"An error occurred trying to start process 'C:\temp\email.msg' with working directory 'C:\Users\pharr\source\repos\CreateEmailSpike\CreateEmailSpike\bin\Debug\net7.0'. The specified executable is not a valid application for this OS platform."}

There is nothing special about my code but here it is just in case. I am hoping you have a suggestion. I haven't found one as yet.

`// See https://aka.ms/new-console-template for more information using MsgKit; using MsgKit.Enums;

Console.WriteLine("Hello, World!");

string attachmentFileName = @"c:\temp\PSA-Invoice-382.pdf";

using var email = new Email( new Sender("someuser@cc.com.au", "Some User"), new Representing("tinkerbell@neverland.com", "Tinkerbell"), "Hello Neverland subject"); email.Recipients.AddTo("someuser@cc.com.au", "Some User"); email.Recipients.AddCc("crocodile@neverland.com", "The evil ticking crocodile"); email.Subject = "This is the subject"; email.BodyText = "Hello Neverland text"; email.BodyHtml = "Hello Neverland html"; email.Importance = MessageImportance.IMPORTANCE_HIGH; email.IconIndex = MessageIconIndex.ReadMail; email.Attachments.Add(attachmentFileName); try { string emailFileName = @"C:\temp\email.msg"; string dir = Path.GetDirectoryName(emailFileName)!; email.Save(emailFileName); if (File.Exists(emailFileName)) { System.Diagnostics.Process.Start(emailFileName); } } catch (Exception ex) { var s = ex.ToString();// throw; } `

Sicos1977 commented 1 year ago

You probably don't have an application installed that can handle MSG files