And so, here is the code:
import com.example.sendsapp.MailSenderClass; import com.example.sendsapp.R; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class ExtendedMail extends Activity { Context mainContext; String title; String text; String from; String where; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hotline); mainContext = this; Button buttonsend = (Button) findViewById(R.id.buttonsend); buttonsend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sender_mail_async async_sending = new sender_mail_async(); async_sending.execute(); } }); } private class sender_mail_async extends AsyncTask<Object, String, Boolean> { ProgressDialog WaitingDialog; @Override protected void onPreExecute() { WaitingDialog = ProgressDialog.show(ExtendedMail.this, "Отправляем сообщение...", true); } @Override protected void onPostExecute(Boolean result) { WaitingDialog.dismiss(); Toast.makeText(mainContext, "Отправлено", Toast.LENGTH_LONG).show(); ((Activity)mainContext).finish(); } @Override protected Boolean doInBackground(Object... params) { try { title = ((EditText)findViewById(R.id.editText1)).getText().toString(); text = ((EditText)findViewById(R.id.editText2)).getText().toString(); text1 = ((EditText)findViewById(R.id.editText3)).getText().toString(); from = "myappmail@mail.as"; where = "mymail@mail.as"; MailSenderClass sender = new MailSenderClass("myappmail@mail.as", "password"); sender.sendMail(title, text, from, where); } catch (Exception e) { Toast.makeText(mainContext, "Ошибка отправки сообщения!", Toast.LENGTH_SHORT).show(); } return false; } } } Here is the error log:
05-30 12:09:56.043: I/Choreographer(6360): Skipped 272 frames! The application may be doing too much work on its main thread. 05-30 12:09:56.233: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090000} 05-30 12:09:56.243: D/dalvikvm(6360): GC_FOR_ALLOC freed 20K, 15% free 4752K/5580K, paused 0ms, total 0ms 05-30 12:09:56.243: I/dalvikvm-heap(6360): Grow heap (frag case) to 5.726MB for 1104672-byte allocation 05-30 12:09:56.253: D/dalvikvm(6360): GC_FOR_ALLOC freed 1K, 13% free 5830K/6660K, paused 10ms, total 10ms 05-30 12:09:56.263: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090003} 05-30 12:09:56.273: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090004} 05-30 12:09:56.273: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090005} 05-30 12:09:56.283: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090006} 05-30 12:09:56.293: D/dalvikvm(6360): GC_FOR_ALLOC freed 11K, 8% free 6993K/7528K, paused 0ms, total 0ms 05-30 12:09:56.303: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090007} 05-30 12:09:56.303: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090008} 05-30 12:09:56.313: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090009} 05-30 12:09:56.323: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f09000a} 05-30 12:09:56.333: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f09000b} 05-30 12:09:56.333: D/dalvikvm(6360): GC_FOR_ALLOC freed 5K, 7% free 8429K/8972K, paused 0ms, total 0ms 05-30 12:09:56.343: W/Resources(6360): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090002} 05-30 12:10:03.283: W/IInputConnectionWrapper(6360): showStatusIcon on inactive InputConnection 05-30 12:10:14.503: W/dalvikvm(6360): Unable to resolve superclass of Lcom/example/sendsapp/ExtendedMail; (1630) 05-30 12:10:14.503: W/dalvikvm(6360): Link of class 'Lcom.example.sendsapp.ExtendedMail;' failed 05-30 12:10:14.503: E/dalvikvm(6360): Could not find class 'com.example.sendsapp.ExtendedMail', referenced from method com.example.sendsapp.MailSenderClass$Sender_mail_async.doInBackground 05-30 12:10:14.503: W/dalvikvm(6360): VFY: unable to resolve new-instance 1502 (Lcom/example/sendsapp/ExtendedMail;) in Lcom/example/sendsapp/MailSenderClass$Sender_mail_async; 05-30 12:10:14.503: D/dalvikvm(6360): VFY: replacing opcode 0x22 at 0x0052 05-30 12:10:14.503: W/dalvikvm(6360): Unable to resolve superclass of Lcom/example/sendsapp/ExtendedMail; (1630) 05-30 12:10:14.503: W/dalvikvm(6360): Link of class 'Lcom/example/sendsapp/ExtendedMail;' failed 05-30 12:10:14.503: D/dalvikvm(6360): DexOpt: unable to opt direct call 0x2a70 at 0x58 in Lcom/example/sendsapp/MailSenderClass$Sender_mail_async;.doInBackground 05-30 12:10:14.523: W/dalvikvm(6360): threadid=11: thread exiting with uncaught exception (group=0x5ccbbb20) 05-30 12:10:14.523: D/AndroidRuntime(6360): procName from cmdline: com.example.sendsapp 05-30 12:10:14.523: E/AndroidRuntime(6360): in writeCrashedAppName, pkgName :com.example.sendsapp 05-30 12:10:14.523: D/AndroidRuntime(6360): file written successfully with content: com.example.sendsapp StringBuffer : ;com.example.sendsapp An error occurs when sending a message.