1
votes

I am developing a WPF app in MVVM presentation pattern. I have a grid and I am trying to have an "emailto" hyperlink and when the user clicks that i am trying to export all the data to an excel and open the default email client with a draft new message window(email client could be Lotus/Outlook) and attach the excel as an attachment to the mail. I am able to define a "Mailto" hyperlink and when i click that i am able to open the draft message email window. But i am not sure how to send the excel as an attachment. Any help is greatly appreciated.

2

2 Answers

2
votes

By sending an Excel file you don't mean generating of this file somehow. Right? So you just need to attach a file.

I always use Andrew Baker's MAPI wrapper class which seems to be very reliable and has never failed for last 6 years. It's just 18Kb of C# code and it does exactly what you need.

var message = new MapiMailMessage(subject, body);
message.Recipients.Add(mailAddress);
message.Files.Add(filePath);
message.ShowDialog();
0
votes

You could use Simple MAPI API to solve your problem:

var mapi = new Mapi();
mapi.Logon(IntPtr.Zero);

foreach (var filePath in files)
    mapi.Attach(filePath);

mapi.Send("subject", "body text", true /* show send message dialog to user */);
mapi.Logoff();