Is there any good way to launch UWP mail app through MAPISendMail function with file attachments from desktop app?
mailto:
protocol will launch but it doesn't attach files...
Update 2022-12-06:
To access Windows Runtime API from .NET Framework app, check: Call Windows Runtime APIs in desktop apps - Windows apps | Microsoft Learn
Edit csproj and add <TargetPlatformVersion>8.0</TargetPlatformVersion>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>
</Project>
And also add Windows
reference. HintPath
is mandatory and its important file Windows.winmd
is included in Windows 10 SDK.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Reference Include="Windows">
<HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd</HintPath>
</Reference>
<Reference Include="System.Runtime.WindowsRuntime" />
</ItemGroup>
</Project>
And code:
namespace ConsoleApp76
{
internal class Program
{
static void Main(string[] args)
{
var file = StorageFile.GetFileFromPathAsync(@"C:\filepath").AsTask().Result;
Console.WriteLine(SharedStorageAccessManager.AddFile(file));
}
}
}
A sharing token will be retrieved in string.
7808B122-02DD-4996-A22D-C1D9EEC880E4
You can do it like this: mailto:?ms-attachments=token1,token2,...
Whereas the tokens have been created with SharedStorageAccessManager.AddFile() for the respective files you want to attach.
Note that not all email clients support this format, but the built-in Windows 10 Mail app does support it.