4

I'm using:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

to send email, I need to add some footer to the message, is there any listener or some way that I can edit the message when user clicks "send"?

Thanks!

Edit:

below is the code I used:

private void sendEmail(String recipient, String subject, String message) {
    try {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        if (recipient != null)  emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
        if (subject != null)    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        if (message != null)    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

    } catch (ActivityNotFoundException e) {
        // cannot send email for some reason
    }
}

There is no field like:

android.content.Intent.EXTRA_EMAIL

which lets me supply information to the intent.

Heuristic
  • 5,087
  • 9
  • 54
  • 94

3 Answers3

2

If the email is sent from your own app, then you will need to add the footer before firing the intent.

If the email is sent using any other app (including the default email app), then no, you won't be able to modify it.

EDIT:

In the case above, you will just need to append the signature to the message string, any time before the line

if (message != null)    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • Hi I know what you mean, but what I mean is the footer which always appear at the end of message, something like "posted by ABC iphone client", you do not see it when you are posting but it is appended in the actual post. – Heuristic Jun 08 '11 at 05:13
  • That's the last moment *you* will be able to modify anything. If you do not want that, then you'll have to implement your code in JavaMail. See this question for details: http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android-app – Aleadam Jun 08 '11 at 05:17
1
@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("mailto:")) { 
                try {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.parse(url));
                    emailIntent.setType("message/rfc822");
                    String recipient = url.substring( url.indexOf(":")+1 );
                    if (TextUtils.isEmpty(recipient)) recipient = "loco@wareninja.com";
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mContext.getString(R.string.email_subject));
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mContext.getString(R.string.email_message, " "));

                    mContext.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                }
                catch (Exception ex) {}
            }
            return true;
        }
Yilmaz Guleryuz
  • 9,313
  • 3
  • 32
  • 43
0

You could..

  1. Create a form in your own app with To, Subject, and Text TextEdit fields.

  2. Save those user inputs as String variables.

  3. Append/edit String variables

  4. Pass the finalized variables into your emailIntent.putExtra()'s

Then, your users can decide if they like the changes or not, and just press send.

Anonsage
  • 8,030
  • 5
  • 48
  • 51