2012-03-23 236 views
2

我有以下條件: enter image description here如何發送電子郵件到特定的電子郵件?

如何發送電子郵件至[email protected]submitButton clicklistener?

submitButton.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      //how to send email ?? 

     } 
    }); 

幫助!

+0

見類似的問題[這裏](http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-應用程序) – EdChum 2012-03-23 00:18:59

+0

重複http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application? – 2012-03-23 00:19:38

+0

只有三個現場收件人電子郵件地址,電子郵件主題和電子郵件正文。當我添加上面的字段,如名稱,發件人的電子郵件地址,它是否產生任何問題? – captaindroid 2012-03-23 00:28:20

回答

3

它很簡單。在您的onClick方法簡單地創建和填寫以下Intent

Intent i = new Intent(android.content.Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "subject"); 
i.putExtra(Intent.EXTRA_TEXT , "body"); 
startActivity(Intent.createChooser(i, "Email:")); 
+0

我可以添加發件人電子郵件像'emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,senderEmailAddress); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,senderName); '這個? – captaindroid 2012-03-23 00:33:40

+0

不!因爲'android.content.intent.EXTRA_SUBJECT'指定了電子郵件的**主題** – slayton 2012-03-23 00:34:36

+0

如果你想指定收件人的姓名和電子郵件地址,你可以嘗試使用如下的字符串:'「John Smith 「'。我沒有嘗試過,所以我不知道它是否有效,但它應該只需要幾秒鐘,試試看看它是否有效 – slayton 2012-03-23 00:35:59

相關問題