2

I'm trying to compose and send an email which will include a signature at the bottom of my email content in android. I'm able to send an email but I'm not getting the way that allows me to add my own signature. Do you have any suggestion?

here's my code:

public void addListener() {
                final Button button = (Button) findViewById(R.id.button1);
                button.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                                findViewById = (TextView) findViewById(R.id.t1);
                                Intent i = new Intent(Intent.ACTION_SEND);
                                i.setType("text/plain");
                                i.putExtra(Intent.EXTRA_EMAIL,
                                                new String[] { "some@gmail.com"});
                                /*i.putExtra(Intent.EXTRA_CC,
                                                new String[] { "some@gmail.com" });*/
                                i.putExtra(Intent.EXTRA_SUBJECT, "Android Test");
                                i.putExtra(Intent.EXTRA_TEXT, "Body");
                                //i.putExtra(Intent.EXTRA_TEXT, "signature");
                                try {
                                        startActivity(Intent.createChooser(i, "Choose mail app..."));
                                } catch (android.content.ActivityNotFoundException ex) {                                       
                                }

                        }
                });
        }
z3cko
  • 3,054
  • 8
  • 40
  • 59
  • Please, be more specific on the Android version and on what exactly happens. Try to include 1) what should happen and 2) what happens instead. Thanks. – z3cko Sep 18 '12 at 15:14
  • i'm using android 4.1(api 16). I want to include signature like "Regards " at the end of email body. i have an account on gmail and it does append signature automatically when sent from gmail.com but not able to achieve this with android. – user1680411 Sep 18 '12 at 15:52

1 Answers1

4

I don't think the "signature" is really a different section of an email. I think you can just append your signature to your body.

i.putExtra(Intent.EXTRA_TEXT, "Body" + "\\n" + "Signature");
xbakesx
  • 13,202
  • 6
  • 48
  • 76
  • What if signature has images in it @xbakesx ? – Seshu Vinay Feb 21 '13 at 06:30
  • 1
    You would add it the same way you add an image to an email. First you have to set the mime-type of your email to `text/html` then embed an `` tag. (See this question for details: http://stackoverflow.com/questions/3148486/embedding-image-in-email-in-android) – xbakesx Feb 21 '13 at 14:38
  • So, what will be src of img? i mean which path? where should be the image saved? suppose it is in res/drawable, how it should be done? – Seshu Vinay Feb 21 '13 at 17:17
  • The `src` will depend on where you're getting the image from, and actually where you're getting it from will change a lot of things. Assuming you have it as an `InputStream` or resource, you can use `BitmapFactory.decode...` to read in the bytes, `base64` the data with `Base64.encode(...)`. Read up on Bitmap decoding though, that isn't as easy as it should be : ), if you need more help write up a question, because these comments leave me little room to give examples. – xbakesx Feb 21 '13 at 19:20
  • Cursor comes after the Signature. Any alternate way? – Seshu Vinay Apr 18 '15 at 11:31
  • The cursor will be at the end because all you did was append your signature to the body... I don't see a way around the that. – xbakesx Apr 19 '15 at 11:56