Tutorials Android How to Send an Email with Attachment in Android

How to Send an Email with Attachment in Android

The following code snippet shows to send an email with image attachment in Android using the 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);
}
Total
0
Shares
Leave a Reply

Your email address will not be published.

Previous Post
Android Tutorials

How to Convert Pixels to Density Independent (DP) Pixels

Next Post
How to Configure Google Feedburner Feed for your Blog

How to Configure Google Feedburner Feed for your Blog

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All