Email with attachment - android

i am trying to send an email with an attachment using intent.
the file is a pdf stored in the raw folder. it is less than 200k.
but it shows file too large to attach. Y?
help me pls..
Intent in = new Intent(Intent.ACTION_SEND);
in.setType("application/pdf");
in.putExtra(Intent.EXTRA_EMAIL,new String[]{email.getText().toString()});
in.putExtra(Intent.EXTRA_SUBJECT, "Android Development Course");
Uri uri = Uri.parse("android.resource://deepak.android.samples/raw/android");
in.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(in, "Sending email.."));

use this method
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{"emailaddress"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Body");
String rawFolderPath = "android.resource://" + getPackageName()
+ "/" + R.raw.shortcuts;
// Here my file name is shortcuts.pdf which i have stored in /res/raw folder
Uri emailUri = Uri.parse(rawFolderPath );
emailIntent.putExtra(Intent.EXTRA_STREAM, emailUri);
emailIntent.setType("application/pdf");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Related

how to send .apk file from sdcard via email itent in android?

i want to send .apk file from sdcard via email intent but not getting attachment.
see below codei try this code but not working for me..
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "email id" });
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:/" + "/sdcard/obb/rr.apk"));
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
This code says could not attachment and not getting mail.
Try to change the type of your attachment as below:
emailIntent.setType("application/zip");
thanks for help i got the mail using this one.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email id"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App new 1");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/rr.apk"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Don't use hard coded /sdcard/ there is no guarantee that the SD card will have that path
Instead change
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
to
Uri fileUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separatorChar + "obb" + File.separatorChar + "rr.apk"));
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
Also change
emailIntent.setType("text/plain");
to
emailIntent.setType("application/zip");

Send email with attachment in Android. Works on Gmail but not on Outlook

So from my Android app I can send emails with attachment on Gmail. On outlook looks like it is attaching the file (.txt), but when I open the mail there is no attached file.
This is my code:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
Uri uriFileToShare = Uri.fromFile(file);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, file.getName());
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uriFileToShare);
this.startActivityForResult(Intent.createChooser(emailIntent, activity.getString(R.string.send)+" "+file.getName()+" "+activity.getString(R.string.by_email)),code);
I have tried different solutions but no result.
The file of course exists and is not empty. As I said, on Gmail is correctly attached.
Any idea?
This code worked for me on outlook file attachment.
public static void emailLog(Context context) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
String filePath = fileDir + "/" + fileName;
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
File recordingFile = new File(filePath);
Uri fileUri = Uri.fromFile(recordingFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
context.startActivity(Intent.createChooser(emailIntent, "Some text..."));
}

Unable to attach an attachment with email in android

I am trying to send an email with an attachment, I have created a pdf file as well as a text file, for attaching a text file and sending an email i am using this code
email.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String path = "/ScriptEmails/"+ filename;
String filepath = Environment.getExternalStorageDirectory()+File.separator+"Screenwriter"+File.separator+path;
sendEmail ("text", "enter email here", "Script from scriptwrite android", "Your script is attached", filepath);
And the send email function is like this:
public void sendEmail (String attachmentType, String emails, String subject, String text, String filePath)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType(attachmentType);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emails});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+filePath/*mnt/sdcard/Myimage.jpeg"*/));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
now, the path is correct, the file name is correct, yet upon sending an email, it says, the attachment couldn't be send.
What i think is that i am not putting right ATTACHMENT TYPE for my file type.
What would be the attachment type for a text file and what would be an attachment type for a pdf file?
for text file i am using (txt/plain) is this correct?
Try this code for attach file with email client.
File file = new File(path);
Uri pngUri = Uri.fromFile(file);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_BCC,new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);
Path should be like below.
final String path = Environment.getExternalStorageDirectory().toString()+ "/.....your_path";
For attaching the PDF you need to set the type as "application/pdf" and for text file "text/plain" below :
File externalStorage = Environment.getExternalStorageDirectory()+File.separator+"Screenwriter"+File.separator+path;
Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/" + "yourfilename.pdf"));
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));

how to send image via email in android?

I am developing an application in which i have to send an image via email, I tried with
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "xyz#gmal.com");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "message");
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.a));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
but its giving me as gmail has stopped unfortunately.How can I send an image via email,
Thanks in advance.
Get the image storage path by using the file,
File img = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/", imagename+".png");
Convert that file path in to Uri
Uri imageuri = Uri.fromFile(img);
Send the image via email using
Intent send_img = new Intent(Intent.ACTION_SEND);
send_img.putExtra(Intent.EXTRA_EMAIL, "xyz#gmal.com");
send_img.putExtra(Intent.EXTRA_SUBJECT, "email_subject");
send_img.putExtra(Intent.EXTRA_STREAM, imageuri);
send_img.putExtra(Intent.EXTRA_TEXT, "message");
send_img.setType("text/plain");
send_img.setType("image/png");
startActivity(Intent.createChooser(send_img, "Send Email..."));

How do I attach a .txt file to an email?

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

Categories

Resources