Email Attachment images cant Send - android

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

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

android BCC is not working for email

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

Why sending mail is not working on my code ?

Trying to send mail with attached file - and i don't know why this code is not working .. the mail is not sending
public void SendMailWithAttached(String fileToSend, String mailToSend)
{
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("vnd.android.cursor.dir/email");
sharingIntent.putExtra(Intent.EXTRA_EMAIL, fileToSend);
sharingIntent.putExtra(Intent.EXTRA_STREAM,mailToSend);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
startActivity(Intent.createChooser(sharingIntent, "Send email"));
}
Here is what I do to send a file as an attachment:
File effFile = new File(toPath, files[0]);
Uri effU = Uri.fromFile(effFile);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_STREAM, effU);
startActivity(Intent.createChooser(i, "Email:"));
The i.setType("text/plain"); command didn't work when I tried others.

How to send image file in the body of the email

I know this question is already ask in the stack overflow, and I looked around them but don't get any clue. Actually I have written code for sending an image file as an attachment to my mail and its working fine. The code I used for sending an image file as an attachment is shown below. Can anyone tell me what are the changes I need to do to send the image file in the body of mail? Any clue will be helpful.
Code for sending the image as an attached file
Uri imageUri = Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" + fileNameArray.get(position));
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/png");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(i, "Send email"));
only work in device not in android emulator..
http://blogingtutorials.blogspot.com/2010/12/send-email-with-attached-file-in.html
Try using the following intent:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
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://"+ sPhotoFileName));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

How to Attach files with sending mail in android application?

I am sending mail through my application.
For that I am using following code.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
It just work fine but i want to attach an xml file with it.
Is it possible? How?
There are lots of similar questions asked with perfect solution in Stack Overflow already.
You can have look to few : here and here and here
Solution is to use with email intent : one more putExtra with Key-Extra_Stream and Value-uri to file.
And please go through the FAQ to undersatand How to better benifit from the site.
String pathname= Environment.getExternalStorageDirectory().getAbsolutePath();
String filename="/MyFiles/mysdfile.txt";
File file=new File(pathname, filename);
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, "Title");
i.putExtra(Intent.EXTRA_TEXT, "Content");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
i.setType("text/plain");
startActivity(Intent.createChooser(i, "Your email id"));
ACTION_SEND_MULTIPLE should be the action and then emailIntent.setType("text/plain"); followed by:
ArrayList<Uri> uris = new ArrayList<Uri>();
String[] filePaths = new String[] {"sdcard/sample.png", "sdcard/sample.png"};
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
For sending an attachment with gmail:
File should be on External storage device or created in External storage device
For that you need to add the following to Android Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
get External path by
String pathname= Environment.getExternalStorageDirectory().getAbsolutePath();
Create a new file by
File myfile=new File(pathname,filename);
Write to file based on whatever logic you are applying
Now the Intent
Intent email=new Intent(android.content.Intent.ACTION_SEND);
email.setType("plain/text");
Put Extras
email.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(myfile)); email.putExtra(Intent.EXTRA_SUBJECT, "my email subject");
email.putExtra(Intent.EXTRA_TEXT, "my email text");
Start Activity
startActivity(Intent.createChooser(email, "E-mail"));

Categories

Resources