0

I am using the stock code found here to add attachments to an email. It works fine in Android. When I run it on iOS, everything works except there is no attachment on the message. The mail client launches and I see the address, subject, and message all filled out but no attachment. Is there a setting somewhere in order for this to work on iOS?

            var message = new EmailMessage {
                Subject = "Log Files",
                To = new List<string>(new[] { "developer@test.com" }),
                Body = builder.ToString()
            };

            var fn = "Attachment.txt";
            var file = Path.Combine(FileSystem.CacheDirectory, fn);
            File.WriteAllText(file, "Hello World");

            message.Attachments.Add(new EmailAttachment(file));

            await Email.ComposeAsync(message);

I already have the following in the Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>mailto</string>
</array>

And the weird thing is that I can see that the message object has an attachment on it. Is there a debug setting where I could see more diagnostics as to why the attachment isn't getting added in iOS?

Josh
  • 10,352
  • 12
  • 58
  • 109
  • Try looking at the iOS console log output to see if the OS is rejecting the attachment – SushiHangover Jul 26 '21 at 17:17
  • @SushiHangover I don't see any errors and I'm not getting any invalid file exception errors. – Josh Jul 26 '21 at 21:33
  • Every email client is different and may only support specific file extensions, or none at all. You can try it with other email clients. – Adrain Jul 27 '21 at 02:16
  • @AdrainZhu-MSFT This was tested against Gmail and Outlook. Neither pop the attachment up. On Android they do. Does it have to do with this being a development build versus a production release? I just copied the sample code into a brand new project and ran it and same thing, no attachment. – Josh Jul 27 '21 at 13:08

2 Answers2

0

Everything works fine on my side , the email was sent with attachment as expected.

enter image description here

I'm using Outlook to test.

If possible could you attach a basic project which could reproduce the issue here ?

ColeX
  • 14,062
  • 5
  • 43
  • 240
  • I'll mark your answer as correct but I'll follow up with my particular situation in case anyone else runs into it. – Josh Jul 28 '21 at 18:59
0

The code does, in fact, work on an iPad I have that has just the Mail app installed. My particular case is an iPhone 11 with no Mail app installed, just the GMail app. Calling this app directly drops the attachment for no reason. When I uninstalled the Gmail app entirely, installed the Mail app and popped mail off of Gmail inside that app, things worked as intended. Too bad there isn't a callback that states whether the client attached the document or not.

Josh
  • 10,352
  • 12
  • 58
  • 109