通过SMTP(Gmail)示例类在Android上发送电子邮件

【通过SMTP(Gmail)示例类在Android上发送电子邮件】吾生也有涯,而知也无涯。这篇文章主要讲述通过SMTP(Gmail)示例类在Android上发送电子邮件相关的知识,希望能为你提供帮助。
This requires the user to enter his/her google gmail information but still useful if you can' t use the normal Email/Gmail apps via their intents.

  1. package org.apache.android.mail;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9.  
  10. public class SendMail extends Activity {
  11. /**
  12.   * Called with the activity is first created.
  13.   */
  14. @Override
  15. public void onCreate( Bundle icicle) {
  16. super.onCreate( icicle) ;
  17. setContentView( R.layout.main) ;
  18. final Button send = ( Button) this.findViewById( R.id.send) ;
  19. final EditText userid = ( EditText) this.findViewById( R.id.userid) ;
  20. final EditText password = ( EditText) this.findViewById( R.id.password) ;
  21. final EditText from = ( EditText) this.findViewById( R.id.from) ;
  22. final EditText to = ( EditText) this.findViewById( R.id.to) ;
  23. final EditText subject = ( EditText) this.findViewById( R.id.subject) ;
  24. final EditText body = ( EditText) this.findViewById( R.id.body) ;
  25. send.setOnClickListener( new View.OnClickListener( ) {
  26. public void onClick( View view) {
  27. GMailSender sender = new GMailSender( userid.getText( ) .toString( ) , password.getText( ) .toString( ) ) ;
  28. try {
  29. sender.sendMail( subject.getText( ) .toString( ) ,
  30. body.getText( ) .toString( ) ,
  31. from.getText( ) .toString( ) ,
  32. to.getText( ) .toString( ) ) ;
  33. } catch ( Exception e) {
  34. Log.e( " SendMail" , e.getMessage( ) , e) ;
  35. }
  36. }
  37. } ) ;
  38. }
  39. }


    推荐阅读