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);
Related
I used below coding and sent pdf to mail.This pdf not attached in mail.pls give me any solution.
File PayslipDir = new File(Environment.getExternalStorageDirectory(), "/sample/");
// Write your file to that directory and capture the Uri
String strFilename =string3;
File htmlFile = new File(PayslipDir, strFilename);
// Save file encoded as html
Uri htmlUri = Uri.fromFile(htmlFile);
System.out.println("uri"+htmlUri);
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Pdf attachment");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hi PDF is attached in this mail. ");
emailIntent.putExtra(Intent.EXTRA_STREAM, htmlUri);
PDFViewerActivity.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));
below code works fine for me:-
sPhotoFileName=Environment.getExternalStorageDirectory()+"/sankettest/siteriskassesment.png";
send.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"me#gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:///"+ sPhotoFileName));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/sanket test/siteriskassesment.png"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
Hope this works
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/MyPdf.pdf"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
You need to change
emailIntent.setType("application/pdf");
to
emailIntent.setType("text/html");
I hope it will be helpful !!
emailIntent.putExtra(android.content.Intent.EXTRA_BCC,
new String[] {"postcards#in-touchmobile.com"});
I have tried with this code, but bcc can not include in my gmail application.
My full code is
Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(
Intent.EXTRA_EMAIL,
new String[] { Constants.EMAIL });
emailIntent.putExtra(
android.content.Intent.EXTRA_TEXT,
Html.fromHtml(str));
emailIntent.putExtra(
android.content.Intent.EXTRA_BCC,
new String[] { "postcards#in-touchmobile.com" });
emailIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT,
Constants.Subject);
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(screenshotUri);
emailIntent.putParcelableArrayListExtra(
Intent.EXTRA_STREAM,
uris);
startActivity(emailIntent);
startActivity(emailIntent);
I have changed my code like above one..but still not working..
Try in this manner
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/Myimage.jpeg"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Must do this thing emailIntent.setType("application/image");
Checked and let me know
change the type of Intent from image/png and application/octet-stream to plain/text like
emainIntent.setType("plain/text");
and for attaching files to email see here
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"));
}
I am fairly new to android and I am having a problem with the email. I am trying to attach a text file to an email and send it, but when I do I get a "File too large" error. This is my first time setting up email within an application, can someone please help?
Code:
File myFile = new File(Environment.getExternalStorageDirectory() + "/test.txt");
Uri uri = Uri.fromFile(myFile);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "person#gmail.com" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a test.");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);
Hello , try this one.
public void sendMail(String[] mailTo,String[] cc,String subject, String body, String attachmentFilePath)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
emailIntent.setType("plain/text");
if(mailTo!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,mailTo);
if(cc!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_CC, cc);
if(subject!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
if(body!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
if(mailTo!=null)
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+attachmentFilePath));
context.startActivity(emailIntent);
}
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..."));