Lena
Lena

Reputation: 71

Email is not appearing in "TO" field

In the app that I am developing, in the settings-->about-->I have a button which says "contact us", this button is supposed to send an email from the user to me.

This is my code:

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about_app);

        ImageButton email=(ImageButton)findViewById(R.id.email_imbtn);
        email.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent(Intent.ACTION_SENDTO);
                intent.setData(Uri.parse("mailto:")); // only email apps will handle this
                intent.putExtra(Intent.EXTRA_EMAIL, getString(R.string.email_address));
                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));

                if (intent.resolveActivity(getPackageManager()) != null)
                {
                    startActivity(intent);
                }
                else
                    Toast.makeText(About.this,  "משהו השתבש בניסיון פתיחת תוכנת האימייל", Toast.LENGTH_SHORT).show();
            }
        });
    }

The email is not appearing in the "TO" field

enter image description here

How can I fix it?

Upvotes: 1

Views: 40

Answers (3)

Vajira Lasantha
Vajira Lasantha

Reputation: 2513

I use following code to send an email from my app.

mailMe.setOnClickListener(new View.OnClickListener() {
              public void onClick(View paramAnonymousView) {
                  Intent emailActivity = new Intent(Intent.ACTION_SEND);

                    emailActivity.putExtra(Intent.EXTRA_EMAIL, getResources().getString(R.string.email));

                    emailActivity.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name));

                    //you can specify cc addresses as well
                    // email.putExtra(Intent.EXTRA_CC, new String[]{ ...});
                    // email.putExtra(Intent.EXTRA_BCC, new String[]{ ... });

                    //set up the message body
                    //emailActivity.putExtra(Intent.EXTRA_TEXT, message);

                    emailActivity.setType("message/rfc822");
                    startActivity(Intent.createChooser(emailActivity, "Complete action using"));
              }
        });

Hope this will help someone.

Upvotes: 1

sanky jain
sanky jain

Reputation: 873

I think you missed adding receiver name name in mail to

Set the receiver email as below

intent.setData(Uri.parse("mailto:" + "[email protected]"));

Upvotes: 1

Elvis Chweya
Elvis Chweya

Reputation: 1530

Use

intent.setData(Uri.fromParts("mailto", getString(R.string.to_email_address), null));

Instead of

intent.setData(Uri.parse("mailto:")); 

Upvotes: 3

Related Questions