Displaying the To address prefilled in Email Intent? - android

I am not able to pre fill the TO field in Email client to the "to" address mentioned in the extras here:
EmailImage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent it = new Intent(Intent.ACTION_SEND_MULTIPLE);
it.putExtra(Intent.EXTRA_EMAIL, "toaddress#gmail.com");
it.putExtra(Intent.EXTRA_SUBJECT, "Regarding Policy Info");
it.putExtra(Intent.EXTRA_TEXT, "When is my next Premium due");
//it.setType("text/plain");
it.setType("message/rfc822");
startActivity(it);
}
});
What is the problem?
Thanks
Sneha

You need to put the address in an array:
it.putExtra(Intent.EXTRA_EMAIL, new String[] {"toaddress#gmail.com"});
See here.

I've got something like this and its works:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));

When using ACTION_SEND_MULTIPLE,
You have to provide an array of String for Intent.EXTRA_EMAIL Binyamin Sharet shown you.
If the requirement is to provide only one Address then use Intent.ACTION_SEND.

Try this
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"","your email"});

This worked for me:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "someone#gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, edt_msg.getText().toString());
emailIntent.putExtra(Intent.EXTRA_SUBJECT, edt_subjct.getText().toString());
emailIntent.setType("message/rfc822");
Uri uri = Uri.parse("file://" + file_img_capt);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);

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);

Email Intent works some layouts but doesn't work some layouts

I want to connect gmail . My code works on one layout(one screen) but my code doesn't work on 4 layouts(views)
How can I fixed?
Button btn_mail = (Button) findViewById(R.id.btnMail);
btn_mail.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String content="Aşağıda çeşitli ürünler yer almaktadır.Bu ürünlerin analizi bilgilerinin yapılıp,tarafımıza dönüş yapılmasını rica ediyoruz.\n"
+"Uludağ Gazoz 1lt-Cam Şişe\n"
+"Uludağ Gazoz 250ml-Plastik\n" +
"Uludağ Soda Premium 330ml\n"+"Üç ürün için analiz dökümantasyonu hazırlamanızı rica ediyoruz.\n"+"İyi Çalışmalar...";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"m.keskin#uludag.com.tr"});
intent.putExtra(Intent.EXTRA_SUBJECT, "ÜRÜN GRUPLARI ANALİZi");
intent.putExtra(Intent.EXTRA_TEXT, content);
startActivity(Intent.createChooser(intent, "Send email"));
}
});
Try this code it works on every layout
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject");
String body = "Aşağıda çeşitli ürünler yer almaktadır.Bu ürünlerin analizi bilgilerinin yapılıp,tarafımıza dönüş yapılmasını rica ediyoruz.\n"
+"Uludağ Gazoz 1lt-Cam Şişe\n"
+"Uludağ Gazoz 250ml-Plastik\n" +
"Uludağ Soda Premium 330ml\n"+"Üç ürün için analiz dökümantasyonu hazırlamanızı rica ediyoruz.\n"+"İyi Çalışmalar...";emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,body);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Sending email with link does not recieved with link

Im trying to send an email from my app, i see the link as should in my email client on my android, but when i check the email receiver, there is no links.
Here is my Code:
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "" });
emailIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT,
MainActivity.getCurrentActivity().getString(
R.string.mailTitle));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
Html.fromHtml(text));
'text' is html.
Thank You.
Try this one
private void sendMail(String[] emailaddressList)
{
Intent sendIntent;
sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/html");
String body="Go to this link \n\n\n";
String link=Html.fromHtml(body)+"\"https://www.google.com"";
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Mail test");
sendIntent.putExtra(Intent.EXTRA_TEXT, link);
sendIntent.putExtra(Intent.EXTRA_EMAIL,emailaddressList);
startActivity(Intent.createChooser(sendIntent, "Send Mail"));
}

Android : how to open a mail composer view?

I just want to know how to open Mail Composer in Android.
With iOS, I would do something like this :
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
[controller setSubject:#"Mail subject"];
[controller setMessageBody:#"Mail body" isHTML:bool];
[controller setToRecipients:recipientsList];
if(controller) [self presentModalViewController:controller animated:YES];
How about Android ?
Thanks a lot.
Intent intent=new Intent(Intent.ACTION_SEND);
String[] recipients={"xyz#gmail.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT,"abc");
intent.putExtra(Intent.EXTRA_TEXT,"def");
intent.putExtra(Intent.EXTRA_CC,"ghi");
intent.setType("text/html");
startActivity(Intent.createChooser(intent, "Send mail"));
The list of apps can be limited to email apps only by using ACTION_SENDTO.
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
See https://developer.android.com/guide/components/intents-common.html#Email
If you want to open only the email clients, then:
Intent intent = new Intent(Intent.ACTION_SEND);
String[] recipients = {"wantedEmail#gmail.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, "emailTitle:");
intent.putExtra(Intent.EXTRA_CC, "ghi");
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Send mail"));
Mostly similar to the accepted answer, with different MIME type.
Like this:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] emailTo});
emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[]{emailCC});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
context.startActivity(Intent.createChooser(emailIntent, context.getString("send email using:")));
You can find more details here: http://mobile.tutsplus.com/tutorials/android/android-email-intent/

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"));

Categories

Resources