I'm using javax.mail.Authenticator to send an Email but I'm got nothing. When I'm try to less secure my gmail I'm still not get an email. Don't know what I;m did wrong, but there are no error in my code.
I'm just remind something. Some time this code got an broken pipe error. But it very rarely.
This is my MainActivity.java
package com.example.yggdrasil.sendmail;
import android.os.Bundle;
import android.app.Activity;
import android.os.Environment;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
send = (Button) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final GMailSender sender = new GMailSender("fxxxxxxxx@gmail.com",
"xxxxxxxxx");
new AsyncTask<Void, Void, Void>() {
@Override public Void doInBackground(Void... arg) {
try {
sender.sendMail("This is Subject",
"This is Body",
"aaaaaaaaa",
"xxxxxxxxx@gmail.com");
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Toast.makeText(getApplicationContext(), "Email send", Toast.LENGTH_SHORT).show();
}
}.execute();
Toast.makeText(getApplicationContext(), "After Execute", Toast.LENGTH_SHORT).show();
}
});
}
}