Search code examples
xamarinemail-attachmentsxamarin.essentials

Xamarin EmailAttachment does not add attachment on iOS


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[] { "[email protected]" }),
                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?


Solution

  • 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 ?