我使用javax.mail.Authenticator发送电子邮件,但我什么都没得到。当我试图减少我的Gmail邮件时,我仍然没有收到电子邮件。不知道我做错了什么,但我的代码中没有错误。
我只是提醒一些事情。有时这段代码出现了管道错误。但它很少。
这是我的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();
}
});
}
}