unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.93k stars 725 forks source link

Support adding attachments to e-mails #2432

Open MartinZikmund opened 4 years ago

MartinZikmund commented 4 years ago

What would you like to be added:

Uno Platform implementation of EmailManager currently does not support e-mail attachments. The problem is that Andorid and iOS support file-based attachments only, however UWP API is fully based on streams. There would be two options:

Why is this needed:

To send files with e-mail. It is often used for sending crash-dumps.

For which Platform:

davidjohnoliver commented 4 years ago

Option # 1 is prefererable from a point of view of compatibility with existing code - certainly clean-up afterwards would be a must.

For option # 2, Uno.UI.Toolkit would be the place for it.

For that matter they're not mutually exclusive, both options could exist side-by-side.

MartinZikmund commented 4 years ago

@davidjohnoliver I am only worried that when we do both, microsoft/microsoft-ui-xaml#1 will be immediately discoverable and the developer will never find out that microsoft/microsoft-ui-xaml#2 is the more efficient choice (unless they explicitly check the docs, but you cannot check docs for everything 😀)

davidjohnoliver commented 4 years ago

Valid, but I think the same problem would exist if we were to only implement # 2: people will see that the UWP method is NotImplemented and they'll figure that it's just not supported.

Discoverability is hard!

MartinZikmund commented 4 years ago

@davidjohnoliver Okay - what about doing both and add a comment to microsoft/microsoft-ui-xaml#1 that suggests using microsoft/microsoft-ui-xaml#2 instead. Potentially there could be a Roslyn Analyzer in the future as well, with such a suggestion.

Last question - when to do the backup cleanup in case it, for some reason, fails after the e-mail is sent? Startup could work, but we want to launch as fast as possible. It could run asynchronously though. And the deletion after sending should fail only occasionally anyway.

davidjohnoliver commented 4 years ago

Sure, some remarks in the xml doc of # 1 drawing attention to # 2 (and vice versa) would make sense.

For the backup cleanup - maybe do it the next time the app tries to send an email attachment? Agreed we wouldn't want to slow down launch for this case.

MartinZikmund commented 4 years ago

One thing I am worried - if using the API is a one time thing, we would have a dead weight adding to the app size forever there 😕

Soap-141 commented 1 year ago

Any update on this?

jeanplevesque commented 1 year ago

FYI https://github.com/microsoft/WindowsAppSDK/issues/3433

marwalsch commented 1 year ago

Xamarin.Essential's implementation of this API has the somewhat narky behaviour of just silently falling back to mail-URIs should the device's provided API be unavailable. If I am not mistaken Uno currently does the same.

if (MFMailComposeViewController.CanSendMail)
{
        await ComposeEmailWithMFAsync(message);
}
else
{
       await ComposeEmailWithMailtoUriAsync(message);
}

For plain E-Mails this is mostly a non.issue, but since mail-URIs do not support attachments they just end up getting scrapped while letting the API's consumer know nothing of this.

(On iOS this can become quite the nuisance as MFMailComposeViewController.CanSendMail may return false despite the Mail App being apparently configured correctly. I could reproduce this on two devices with an uneven mix of different iOS- and device-versions, third party mail apps and a lot of tough luck.)

Hence my suggestion is to not adopt the same mistake and let the user know of that case, perhaps through throwing an exception when an attachment is passed but the fallback initiated.

jeromelaban commented 1 year ago

A possible workaround is to use MAUI essentials, until uno supports EmailManager.