Sending Image as attchment from assets - android

Here is my code It does sends the mail but without any Image as attachment
EditText eto=(EditText)findViewById(R.id.etxtTo);
EditText esub=(EditText)findViewById(R.id.etxtSubject);
String to=eto.getText().toString();
String sub=esub.getText().toString();
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/image");
//emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//String filePath = ImageDetailActivity.this.getResources().getAssets()+"/"+file;
//Log.d("file address",filePath);
//Log.d("file address method2","file:///android_assets/"+file);
File ff=new File(filePath);
pngUri=Uri.fromFile(new File("file:///android_assets/"+file));
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, sub);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.parse("file:///android_assets/"+file));
startActivity(Intent.createChooser(emailIntent, "Choose an Email client :"));
The problem here is I am not able to receive Images attached with the mail.
I have tried a lot of method serching for the solution but not able to figure out the problem

Related

Sending mail with attachment in android

I am trying to send a with attachment where the attachment file could be any type of file(like txt,image,pdf etc) from a sd card.
I used these
String filelocation="file:/"+attachment_file_path1.getText().toString();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent.setType("text/plain");
String to[] = {"destination#yahoo.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "bodyyyyyyyyy");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filelocation));
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "my mail");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
N:B: if i print the attachment_file_path1.getText().toString() it shows like "/storage/sdcard0/myfolder/my.txt"
my email is sent to the destination but my attachment is not sent.
How can i solve the problem??
Change your emailIntent.setType(text/plain) to emailIntent.setType("*/*") for allowing to send any file type.
Path format is :
file:///sdcard/DumbDumpers/DumbDumper.jpg
you need the extra / as this points to the root directory, i.e.:
file:// + /sdcard/DumbDumpers/DumbDumper.jpg
combined as
file:///sdcard/DumbDumpers/DumbDumper.jpg
In the above snippet you need:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));

How to send a String as html attachment in Android mail?

I would like to attach string as html attachment in android mail,how can I achieve this.Kindly help me with a snippet to do this.Thanks a lot.
Use intent to send email like below way .. and if u want to add some string as attachment u have to save that content into some directory with .html ext and later u can add it as attachment into email intent. [This code for idea it may need few modification as per ur app requirement..]
String emailText = "email message";
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demo#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hi");
emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
String attachContent = "<html> content </html>";
/* this method u have to write, to save the string into html file
into cache or any other dir */
saveFile(getCacheDir()+"/attach.html", attachContent );
File file = new File(root, getCacheWebDir()+"/attach.html");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Android Email Intent Issue

I want to send the email from my android app. If i m using
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
It is opening skype,bluetooth along with the mail client
and if i use
Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
then it is only opening mail client,but in the text body it is adding %20%20 when there is new line
Which approach is suitable to get only mail client and body of the mail containing new lines and spaces.
Try sending it as below:
String subject = "mail subject";
String body = "whatever the mail content is. may include html tags too";
Intent intMail = new Intent(Intent.ACTION_SEND);
intMail.setType("message/rfc822");
intMail.putExtra(Intent.EXTRA_SUBJECT, subject);
intMail.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
startActivity(Intent.createChooser(intMail, "Send Email..."));
Try to use this code. You can keep subject, body etc as optional. It only opens email client and gives right output.
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Body);
startActivity(Intent.createChooser(emailIntent, "Email:"));

Sending e-Mail in Android

I need to send an e-mail from my Android application. So, I send 2 parameters ( e-mail and subject) to the e-mail client app, but when app opens e-mail client, there is only subject parameter added, and email parameter is not set.
How I can fix this?
String getMail = email.toString();
Log.d("GET MAIL:",getMail);
String subject = "Subject";
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
// need this to prompts email client only
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent,"Choose E-mail client:"));
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
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, "From App");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Change emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);
to:
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{getMail});
getMail should be a string array...

Showing zero byte pdf file in email attachment in Android

I am sending a pdf file in email attachment, attachment is going successfully in email and it is showing me in email as attachment, but when i download this pdf it having no content i.e. it's size is zero byte.
Am I missing some permission? or Any solution regarding this?
Here is my code
private void emailSend(String emailString, String subject, String pdfPath){
String[] email = { emailString };
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"MY body");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
Finally i got the solution to my problem from this post.
I use
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(pdfPath)));
instead of
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));
it resolved my issue.
Thanks
I've done this for sending 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:"));

Categories

Resources