简体   繁体   中英

Android - sending email from app

I am facing problems in sending email from an Android app. It works intermittently and unreliably. Most of the times, it is stuck in Outbox, in 'Sending..' state.

I know this is a oft-repeated question here, but I am asking it again because I have tried quite a few variations in code, and none of them seem to work RELIABLY. Some forums also say that this is GMail app's fault; and I have tried 'refreshing the outbox folder' and 'disabling and enabling sync', but nothing seems to do the trick.

Here is my code:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "emailText");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("application/zip");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/mnt/sdcard/myFolder/myFile.zip")));
startActivity(Intent.createChooser(emailIntent, "send email"));
finish();
  1. Could someone explain why wouldn't this work?
  2. What should be the value for setType()? Where can I find a list of available values?
  3. Is it because I am trying to send a .zip file? If so, would other archive formats work?

Thanks a lot for your help.

EDIT: I suspect that the issue is with file format (.zip). Other file formats work just fine. I have abandoned this approach and gone for TCP with my own server listening for data.

The reason why it could be stuck in the sending state is because depending on the SIZE of the zip file, it has to add it to the email.. If its too large (over 30 MB) it might hang and get denied by google, since google does not allow the sending of over 30MB in an email. This is just a guess, but try sending a small file and see if this is the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM