The following code snippet shows to send an email with image attachment in Android using Intent method.

public static void sendEmail(Context context, String subject, String message, String imagePath) {
	Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
	emailIntent.setType("plain/text");
	emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
	emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
	
	if (imagePath != null && imagePath.length() > 0) {
		File file = urlToFile(imagePath);
		if (file != null && file.getAbsolutePath() != null)
			emailIntent.putExtra(Intent.EXTRA_STREAM, file.getAbsolutePath());
	}
	
	context.startActivity(emailIntent);
}
Tagged in : Android

Nilanchala

A blogger, a bit of tech freak and a software developer. He is a thought leader in the fusion of design and mobile technologies. He is the author of Xamarin Mobile Application Development for Android Book (goo.gl/qUZ0XV3), DZone MVB and founder of stacktips.com.

Join The Discussion

Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.