Errors in sending email using Eclipse emulator
<p>BackupContactsActivity.java</p>

<pre><code>package com.testing.backup;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class BackupContactsActivity extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    TextView result;
    String msg = "**********Backup Phone Contacts**********\n\n";

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

        Button backup = (Button)findViewById(R.id.btn);
        backup.setOnClickListener(this);
    }

    public void onClick(View view){

        ContentResolver cr = getContentResolver();
        Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

        while(cursor.moveToNext()){
        String name = cursor.getString(cursor.getColumnIndexOrThrow(Phone.DISPLAY_NAME));
        String number = cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER));

        msg += name + "\t\t\t" + number + "\n";         
        }
        result = (TextView)findViewById(R.id.txt);
        result.setText(msg.toString());

        // Recipient's email ID needs to be mentioned.
        String to = "testing@hotmail.com";
        // Sender's email ID needs to be mentioned
        String from = "testing@gmail.com";
        // Email Password
        String password = "testing";
        // Assuming you are sending email from localhost
        String host = "smtp.gmail.com";

        // Get system properties
        Properties properties = System.getProperties();
        // Setup mail server
        //properties.setProperty("mail.smtp.host", host);
        properties.put("mail.smtp.host", host);
        properties.put("mail.smtps.auth", "true");
    properties.put("mail.smtp.starttls.enable", "true");

        // Get the default Session object.
        Session session = Session.getDefaultInstance(properties, null);

        try{
        // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);
            // Set From: header field of the header.
            message.setFrom(new InternetAddress(from));
            // Set To: header field of the header.
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            // Set Subject: header field
            message.setSubject("This is the Backup Contacts Email!");
            // Now set the actual message
            message.setText(msg.toString());

            // Send message
            //Transport.send(message);
            Transport transport = session.getTransport("smtps");
    transport.connect(host, from, password);
    transport.sendMessage(message, message.getAllRecipients());
            System.out.println("Sent message successfully....");
            transport.close();
        }catch (MessagingException mex) {
            mex.printStackTrace();
        }
    }
}
</code></pre>

<p>My Logcat</p>

<pre><code>10-10 12:42:33.773: E/AndroidRuntime(692): FATAL EXCEPTION: main
10-10 12:42:33.773: E/AndroidRuntime(692): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testing.backup/com.testing.backup.BackupContactsActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data/phones from pid=692, uid=10057 requires android.permission.READ_CONTACTS
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.os.Looper.loop(Looper.java:137)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-10 12:42:33.773: E/AndroidRuntime(692):  at java.lang.reflect.Method.invokeNative(Native Method)
10-10 12:42:33.773: E/AndroidRuntime(692):  at java.lang.reflect.Method.invoke(Method.java:511)
10-10 12:42:33.773: E/AndroidRuntime(692):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-10 12:42:33.773: E/AndroidRuntime(692):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-10 12:42:33.773: E/AndroidRuntime(692):  at dalvik.system.NativeStart.main(Native Method)
10-10 12:42:33.773: E/AndroidRuntime(692): Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data/phones from pid=692, uid=10057 requires android.permission.READ_CONTACTS
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.os.Parcel.readException(Parcel.java:1327)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.content.ContentResolver.query(ContentResolver.java:311)
10-10 12:42:33.773: E/AndroidRuntime(692):  at com.testing.backup.BackupContactsActivity.onCreate(BackupContactsActivity.java:32)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.Activity.performCreate(Activity.java:4465)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-10 12:42:33.773: E/AndroidRuntime(692):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-10 12:42:33.773: E/AndroidRuntime(692):  ... 11 more
</code></pre>

<p>Manifest</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testing.backup"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk android:minSdkVersion="15" /&gt;
&lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
&lt;uses-permission android:name="android.permission.INTERNET" /&gt;

    &lt;application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" &gt;
        &lt;activity
            android:name=".BackupContactsActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<p>I would like to extract all the phone contacts (name + number) in the Android phone and put them into a String message, so when i click on the "Backup" button in the application, these contacts information will be sent directly to my email address. I just tried this using the Eclipse emulator and i already added <strong>READ_CONTACTS</strong> and <strong>INTERNET</strong> permissions in my Manifest. But it comes out the problems stated in my logcat. Could someone just help me to troubleshoot the problem? Thanks... <strong>(I did using the real email addresses for both sender and receiver)</strong></p>
