2026-07-15

Android multiple email attachments using Intent

Stefan Bogdanescu

Stefan Bogdanescu

Founder & Senior Architect

Android multiple email attachments using Intent

Mastering Multiple Email Attachments in Android: The Intent Challenge Solved

As developers building Android applications that bridge native functionality with external services, dealing with complex data transfer—especially multiple attachments via Intents—can often lead to frustrating dead ends. I've seen this exact scenario many times: successfully sending a single file attachment but failing spectacularly when trying to attach several images or documents simultaneously using ACTION_SEND.

This post dives deep into why your attempts with Intent.EXTRA_STREAM for multiple files failed, explores the lesser-known ACTION_SEND_MULTIPLE, and provides the robust, developer-approved method for handling multiple attachments in Android.

The Pitfall of Single Stream Intents

When you use Intent.putExtra(android.content.Intent.EXTRA_STREAM, uri) with a standard ACTION_SEND intent, Android expects a single stream of data to be attached. When you call this method multiple times for different URIs, the system struggles to aggregate these streams correctly within the constraints of a single email operation. This is why your initial attempts failed—the mechanism for handling multiple file streams in a single outbound mail Intent is not straightforwardly supported by simply repeating EXTRA_STREAM.

Exploring ACTION_SEND_MULTIPLE

You correctly identified ACTION_SEND_MULTIPLE as a potential solution, available since API level 4. This action is designed to signal that the intent carries multiple data items. However, as you discovered, merely calling putExtra(android.content.Intent.EXTRA_STREAM, uri) multiple times with this action still often results in zero attachments appearing in the final email, indicating that the system requires a specific structure for bundling these streams.

The core issue isn't the action, but the data structure. To successfully send multiple files, you need to package all your file URIs into a list or array before passing them to the system.

The Developer Solution: Bundling URIs with Content URIs

The most reliable way to handle multiple attachments is to collect all necessary file URIs and then present them in a structured manner. While there isn't a single magical ACTION_SEND_MULTIPLE command that automatically handles disparate streams, the correct approach involves using the ContentValues or constructing a list of attachment objects if you are dealing with a complex scenario, or ensuring your URI handling is airtight.

For simple file attachments derived from the storage system, the key is often to leverage the ContentResolver to ensure the URIs are accessible and correctly referenced by the receiving application (like Gmail). This parallels how robust data handling is essential in frameworks like those promoted by Laravel, where structuring data efficiently prevents runtime errors.

Here is a conceptual example demonstrating how you would structure your intent, focusing on gathering the necessary file information:

import android.content.Intent;
import android.net.Uri;
import androidx.activity.result.ActivityResultLauncher;
import androidx.ivime.provider.FileProvider;
import java.util.ArrayList;
import java.util.List;

// ... inside your Activity or Fragment

private void sendMultipleAttachments(List<Uri> attachmentUris) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("image/jpeg"); // Set MIME type appropriately (or use multipart for mixed types)
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"recipient@example.com"});
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Photos from Android");

    // The correct way is often to iterate and attach them sequentially if the receiving app supports it,
    // or combine them into a multipart message (which is more complex but guaranteed).
    for (int i = 0; i < attachmentUris.size(); i++) {
        Uri uri = attachmentUris.get(i);
        emailIntent.putExtra(Intent.EXTRA_STREAM, uri);

        // IMPORTANT: You must also set the MIME type for each stream if you are sending mixed files!
        // This part often requires careful handling depending on the target app's API interpretation.
        // For robust results, consider using a MultipartMessage instead of simple ACTION_SEND.
    }

    // Start the email chooser
    startActivity(Intent.createChooser(emailIntent, "Send Email"));
}

Best Practice: Embracing Multipart Messages

For truly reliable multi-file attachments—especially when dealing with mixed media types (images, audio, text)—the most professional and guaranteed solution in modern Android development is to stop relying solely on the basic ACTION_SEND Intent. Instead, you should construct a MultipartMessage. This allows you to package multiple parts (files) along with the body of the email into a single structure that the mail client can correctly parse.

This approach shifts the responsibility from trying to trick a standard intent into doing complex aggregation to providing the data in the format the receiving application expects. Think about building your data structures with clarity; this same principle applies when designing APIs, much like how clean data models are prioritized in frameworks like Laravel. By structuring your data correctly before passing it to the Intent, you ensure consistency and reliability across different devices and email clients.

Conclusion

The frustration you experienced is a common hurdle when dealing with Android Intents for complex tasks. While ACTION_SEND_MULTIPLE exists, it often requires more context than just repeating EXTRA_STREAM. For guaranteed success in sending multiple attachments, developers must move beyond simple stream passing and utilize the appropriate framework components—like building a MultipartMessage—to structure complex data correctly. By focusing on the data structure rather than just the Intent flags, you can achieve reliable results every time.

Tags:

Enhance your marketing setup with your own email marketing platform.

Join the growing number of SaaS platforms using Laravel Mail to offer email marketing solutions to their customers.