1

i am developing contact form for that need to send email to particular mail id which is fixed....please help me...

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    buttonSend = (Button) findViewById(R.id.buttonSend);
    textTo = (EditText) findViewById(R.id.editTextTo);
    textSubject = (EditText) findViewById(R.id.editTextSubject);
    textMessage = (EditText) findViewById(R.id.editTextMessage);

    buttonSend.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            String to = textTo.getText().toString();
            String subject = textSubject.getText().toString();
            String message = textMessage.getText().toString();
            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL, new String[]{"abcdk@gmail.com"});          
            email.putExtra(Intent.EXTRA_SUBJECT, "subject");
            email.putExtra(Intent.EXTRA_TEXT, "message");
            email.setType("text/plain");
            startActivity(Intent.createChooser(email, "Choose an Email client :"));


        }
    });

But it is not working...

 08-14 09:11:21.559: E/ActivityThread(552): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d4ad38 that was originally bound here
08-14 09:11:21.559: E/ActivityThread(552): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d4ad38 that was originally bound here
08-14 09:11:21.559: E/ActivityThread(552):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
08-14 09:11:21.559: E/ActivityThread(552):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
08-14 09:11:21.559: E/ActivityThread(552):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
08-14 09:11:21.559: E/ActivityThread(552):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
08-14 09:11:21.559: E/ActivityThread(552):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
08-14 09:11:21.559: E/ActivityThread(552):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
08-14 09:11:21.559: E/ActivityThread(552):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
08-14 09:11:21.559: E/ActivityThread(552):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
08-14 09:11:21.559: E/ActivityThread(552):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
08-14 09:11:21.559: E/ActivityThread(552):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
08-14 09:11:21.559: E/ActivityThread(552):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
08-14 09:11:21.559: E/ActivityThread(552):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-14 09:11:21.559: E/ActivityThread(552):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-14 09:11:21.559: E/ActivityThread(552):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-14 09:11:21.559: E/ActivityThread(552):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-14 09:11:21.559: E/ActivityThread(552):  at java.lang.Thread.run(Thread.java:856)
08-14 09:11:21.620: E/StrictMode(552): null
08-14 09:11:21.620: E/StrictMode(552): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d4ad38 that was originally bound here
08-14 09:11:21.620: E/StrictMode(552):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
08-14 09:11:21.620: E/StrictMode(552):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
08-14 09:11:21.620: E/StrictMode(552):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
08-14 09:11:21.620: E/StrictMode(552):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
08-14 09:11:21.620: E/StrictMode(552):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
08-14 09:11:21.620: E/StrictMode(552):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
08-14 09:11:21.620: E/StrictMode(552):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
08-14 09:11:21.620: E/StrictMode(552):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
08-14 09:11:21.620: E/StrictMode(552):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
08-14 09:11:21.620: E/StrictMode(552):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
08-14 09:11:21.620: E/StrictMode(552):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
08-14 09:11:21.620: E/StrictMode(552):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-14 09:11:21.620: E/StrictMode(552):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-14 09:11:21.620: E/StrictMode(552):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-14 09:11:21.620: E/StrictMode(552):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-14 09:11:21.620: E/StrictMode(552):  at java.lang.Thread.run(Thread.java:856)
blackpanther
  • 10,998
  • 11
  • 48
  • 78
sandy
  • 15
  • 5
  • This code is working fine in my case. Check if you have setup your email account in the email client which you are using to handle the intent from your app. – arshu Aug 14 '13 at 09:40

4 Answers4

0

For Sent mail use following code.

final Intent emailIntent = new Intent(
                    android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    new String[] { vendoremail });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    _productList.get(0).ProductName);

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

here..

vendoremail = email id,
_productList.get(0).ProductName = Email description

EDIT :

You have to give permission in AndroidManifest.xml file.

 <uses-permission android:name="android.permission.INTERNET" />
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
0

The best (and easiest) way is to use an Intent:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

Otherwise you'll have to write your own client.

Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
  • Or you can visit this link http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android – Sanket Shah Aug 14 '13 at 09:17
0

change setType()

use this line

email.setType("message/rfc822");

instead of

email.setType("text/plain");
Ketan Ahir
  • 6,678
  • 1
  • 23
  • 45
0

Try this

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("text/plain");
emailIntent .putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipientemail@example.com"});
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "subject");
emailIntent .putExtra(Intent.EXTRA_TEXT   , "body");
startActivity(Intent.createChooser(emailIntent , "Email:"));
mdDroid
  • 3,135
  • 2
  • 22
  • 34