0

I have read this link for sending an email via the GMailSender helper class Sending Email in Android using JavaMail API without using the default/built-in app

But I still have a problem. Nothing happens on clicking the send button.

Here's my java class.

package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class VerificationMail extends Activity implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.verification);
    EditText mailId=(EditText)findViewById(R.id.etEmailID);
    Button bVerify=(Button)findViewById(R.id.bVerifyMail);
    bVerify.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    try {   
        GMailSender sender = new GMailSender("sendermail@gmail.com", "password");
        sender.sendMail("This is Subject",   
                "This is Body", 
                "sendermail@gmail.com",
                "receivermail@gmail.com");   
      //Toast
        Toast t=Toast.makeText(this, "Mail sent", Toast.LENGTH_LONG);
        t.show();
    } catch (Exception e) {   
        Log.e("SendMail", e.getMessage(), e);   
    }
}

}

I have a doubt here. In the parameters for the GMailSender class, is the 1st parameter the sender's mail id?? Also, the toast inside try works and displays "Mail sent" on the screen, but there is no mail sent. There is nothing in the Logcat either.

My GMailSender class and JSSEProvider are same as in the link I have given. Also I added the GMailSender class in my package itself in src, where I have all my other .java files which I have created. JSSEProvider is in a folder called com.provider in src. Is this fine??

I 'll be so grateful if someone can help me out here! Thanks

Community
  • 1
  • 1
yolo101
  • 3
  • 1

1 Answers1

0

Are you doing this in the main Thread ? If yes, probably you have encountered NetworkOnMainThreadException.

Please perform the operation inside AsyncTask

There is no exception shown in logcat is possibly because inside sendMail() there is a try-catch in which catches all the exception without printing any log.

hungr
  • 2,086
  • 1
  • 20
  • 33