2014-04-30 78 views
0

我正在創建一個android應用程序。它有一個反饋表單。現在,當用戶點擊「提交評論」按鈕時,應該將所有詳細信息發送到我的電子郵件地址,即用戶在表單中輸入的所有詳細信息。我在這裏看到很多例子和問題,但沒有得到正確的答案。我不知道該怎麼做。我是Android新手。請幫幫我。如何通過單擊Android應用程序中的提交按鈕發送電子郵件

enter image description here

+0

你有什麼錯誤? – rajshree

+0

可能重複[如何從我的Android應用程序發送電子郵件?](http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application) – Simon

+0

http:///stackoverflow.com/questions/21720640/sending-email-from-android-app-when-click-on-button – rajshree

回答

0
Intent email = new Intent(Intent.ACTION_SEND); 
       email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to}); 
       //email.putExtra(Intent.EXTRA_CC, new String[]{ to}); 
       //email.putExtra(Intent.EXTRA_BCC, new String[]{to}); 
       email.putExtra(Intent.EXTRA_SUBJECT, "subject"); 
       email.putExtra(Intent.EXTRA_TEXT, "message"); 

       //need this to prompts email client only 
       email.setType("message/rfc822"); 

       startActivity(Intent.createChooser(email, "Choose an Email client :")); 

      } 
0

請嘗試對提交按鈕:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
     "mailto","[email protected]", null)); 
intent.putExtra(Intent.EXTRA_SUBJECT, subject); 
intent.putExtra(Intent.EXTRA_TEXT, message); 
startActivity(Intent.createChooser(intent, "Choose an Email client :")); 

如果沒有特定的收件人 - 是這樣的:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
     "mailto",null, null)); 
1

你可以試試這個在您發送按鈕點擊事件:

Intent i = new Intent(Intent.ACTION_SEND); 
      i.setType("message/rfc822"); 
      i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
      i.putExtra(Intent.EXTRA_SUBJECT, "title"); 
      i.putExtra(Intent.EXTRA_TEXT, message);//message is your details 
      try { 
       startActivity(Intent.createChooser(i, "Send mail...")); 
      } catch (android.content.ActivityNotFoundException ex) { 
       Toast.makeText(about.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); 
      } 
0

對於發送電子郵件,您將不得不使用已經配置了正確的電子郵件帳戶的內置/安裝的電子郵件客戶端/應用程序。在android中沒有用於發送郵件的API。發送接收電子郵件使用已由電子郵件應用程序實施的協議。在您的應用中實現它會使其非常複雜。

更好的選擇是調用Web服務並將數據傳遞到服務器並將其存儲在數據庫中。如果你真的想發送電子郵件,那麼在服務器上發送收到的數據作爲電子郵件。根據您使用的服務器,您將能夠找到電子郵件的連接器。

+0

但我不想使用任何內置的android應用程序.. plzz幫助我.. :( – Ruchir

相關問題