Android open emailclient programmatically - android

Is it possible to open an emailclient such as gmail when I click a button in my app?

Yes. You can launch it via Intents.
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));

Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", EMAIL_ADDRESS, null));
up to date way of doing it
i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
startActivity(Intent.createChooser(i, "Send email"));

If above code is not working then try this.
Tested and working
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.item/email");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
startActivity(Intent.createChooser(intent, "Send mail using..."));

This Worked fine for me
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"mobiz#gmail.com"} );
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
startActivity(Intent.createChooser(shareIntent, "Share "));

You can simply use below code when for no attachment:
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:support#mailname.com"));
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
startActivity(Intent.createChooser(emailIntent, "Send feedback"));
For details I recommend to visit:
https://developer.android.com/guide/components/intents-common.html#Email

Related

Find Solution to send email

I am creating utility to send email. In my code i use chooser intent to choose email app to send email. It work perfectly but the problem is that if i use attachment file in this code using Uri then in chooser i choose G-mail, and then G-mail is stopped. If i send email without attachment it work good. Can any one solve my problem. Here is my code.
public void SendEmail() {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setData(Uri.parse("mailto: "));
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL,to);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
// intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send Mail..."));
}
In this code a line is in comment. if i use this line then G-mail is stopped. I am using this line for file attachment. Help me please.
/**Use the below Code Snippet**/
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("vnd.android.cursor.dir/email");
String to[] = {""};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + "Your URI"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Use this code it's works for me correctly:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = {"info#marutinandan.com"};
//String aEmailCCList[] = { "user3#fakehost.com","user4#fakehost.com"};
//String aEmailBCCList[] = { "user5#fakehost.com" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
// emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
// emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "your subject");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "your message body.");
startActivity(emailIntent);

How to send picture on mail automatically in android

I am developing an app in which I want to click Image and automatically after capturing image, the app should send the picture to mail.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imgSaved));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share Image"));
You need to create an intent which will be fired on selection of the image
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("application/image");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Any subject you want to give");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "text you want");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/imageYouSelected.jpeg"));
startActivity(Intent.createChooser(emailIntent, "sending youer email"));
OR
You can use the JAVA API approach like here
try like this may help you,
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "aa#gmail.com" });
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text of email");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imgSaved));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share Image"));

Email Attachment images cant Send

Written a code for send an email along attachment. Once I sent this email it added a garbage value in attachment.
Attached part was encoded in different format.
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"user_one#example.com", "user_two#example.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sPhotoFileName));
i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(mailBody));
startActivity(Intent.createChooser(i, "Send mail..."));
Expected:
It should a attached images files other than encoded string.
Any help would highly appreciate .
Thanks in advance.
File jpegfile = new File(imageDir, "yourfilename.jpeg");
Uri jpegurl = Uri.fromFile(jpegfile);
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpeg"); //
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "mailid#domain.com" });
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail Subject");
intent.putExtra(android.content.Intent.EXTRA_CC, new String[] { "mailid#domain.com" });
intent.putExtra(Intent.EXTRA_TEXT, "Mail body text");
intent.putExtra(Intent.EXTRA_STREAM, jpegurl);
You need to set your intent type to handle images properly, assuming it is a png, as follows.
Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.fromFile(temp));
emailIntent.setType("image/png");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_share_subject));
emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_share_message));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(temp));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
if u Send Jpg image on sen mail...just write i.setType("image/jpeg"); and send any file just write i.setType("image/*");
i've done for send any file from SD card with mail attachment..
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("rar/image");
sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new
File("/mnt/sdcard/download/abc.rar")));
startActivity(Intent.createChooser(sendEmail, "Email:"));

How to add an attachment to an email?

I have this email sending code that does not show a chooser (good). How can I extend it to include a file attachment, without involving a chooser?
// Based on http://stackoverflow.com/questions/3312438
final Intent intent = new Intent(Intent.ACTION_VIEW);
final Uri data = Uri.parse("mailto:user#domain.com?subject=My Sugbject&body=");
intent.setData(data);
startActivity(intent);
try this :
Intent emailintent = new Intent(android.content.Intent.ACTION_SEND);
emailintent.setType("image/jpeg");
emailintent.putExtra(android.content.Intent.EXTRA_TEXT,
"email body here");
emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"test#gmail.com"});
emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject here");
String filName="file:///sdcard/photos/estdemo.jpg";
emailintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ filName));
this.startActivity(emailintent);
Try Following code,
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("photo.jpg"));
startActivity(i);
Use the below code to sent a mail
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("vnd.android.cursor.dir/email");
String to[] = "asd#gmail.com";
sharingIntent.putExtra(Intent.EXTRA_EMAIL, to);
sharingIntent.putExtra(Intent.EXTRA_STREAM,filePath);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"subject");
startActivity(Intent.createChooser(sharingIntent, "Send email"));

Email activity on Android

I want to send email from Android virtual machine to my gmail account.
Problem: but on pressing send button I am getting:
"No application can perform this action"
Here is my code:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("audio/mp3");
//sendIntent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/download/test.mp3"));
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(GlobalVariable.getstrEmail()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(sendIntent, "Title:"));
Try it on a real device itself, it should work. And you need to change the type:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email#example.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
This can help...
Intent openEmailIntent = new Intent(android.content.Intent.ACTION_SEND);
openEmailIntent.setType("plain/text");
openEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[{"zoombie#gmail.com"});
openEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"subject you want");
openEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Any body ");
this.startActivity(Intent.createChooser(openEmailIntent,"Sharing via Email"));
try this....
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emailaddress});
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Categories

Resources