2012-03-31 466 views
0

Sending Email in Android using JavaMail API without using the default/built-in app在機器人發送電子郵件「發送不起作用」

我想根據上面的鏈接,所以我創建了三個班,使電子郵件應用程序爲我的Android,做了一個簡單的佈局,但我可以」讓它工作?當我在模擬器中啓動應用程序並且佈局出現時,我按下發送沒有響應。我懷疑問題在於「發送」。有小費嗎?

我也在清單中添加了。使用權限android:name =「android.permission.INTERNET」

做了一個簡單的佈局...每次我按發送按鈕,它不發送,只打印出「buttonbutton」!

package gaia.feedback.com; 

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

public class GaiaFeedbackActivity extends Activity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     final Button send = (Button) this.findViewById(R.id.send); 
     send.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       try { 
        GmailSender sender = new GmailSender("[email protected]", "password"); 
        sender.sendMail("This is Subject", 
          "This is Body", 
          "[email protected]", 
          "[email protected]"); 
        System.out.println("buttonbutton"); 

       } catch (Exception e) { 
        Log.e("SendMail", e.getMessage(), e); 
        System.out.println("coolcool"); 
       } 

      } 
     }); 

    } 
} 
+0

支票設備?... – 2012-03-31 18:29:49

+0

希望你有包括3個庫完美。 – Bhavin 2012-03-31 18:30:41

+0

@薩米爾尚未完成它!但是,如果我在模擬器或設備上運行,它會產生什麼影響嗎? – 2012-03-31 18:32:23

回答

1

如果您需要發送唯一的郵件,你可以使用下面的線

Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse("mailto:")); 
startActivity(Intent.createChooser(intent, "Send via...")); 
1
If you want to add subject and body then you can use the below method 

private void sendMail(String subject,String body){ 
String mail = "mailto:[email protected]&subject="+subject+"&body="+body; 
Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(mail)); 
startActivity(Intent.createChooser(intent, "Send via...")); 
}