2012-05-31 90 views
-3

我已經嘗試過了......但是當我提交表單時它會轉到撰寫郵件...我只想通過單擊提交按鈕發送郵件...請幫我...從聯繫我們頁面發送郵件到特定的emailid

Intent mailintent = new Intent(android.content.Intent.ACTION_SEND); 
mailintent.setType("text/plain"); 
mailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]   
     {"[email protected]" , "[email protected]"}); 
mailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "info...");   
startActivity(mailintent); 

<uses-permission android:name="android.permission.INTERNET" /> 

清單文件。

+0

什麼是你的問題/問題? –

+0

親愛的我想在提交表單後直接在電子郵件地址上發送聯繫我們表單的詳細信息..但是當我點擊提交按鈕時它會寫郵件.. –

+0

多數民衆贊成在intents/Android工作... android操作系統找到合適的您在Intent中描述的操作活動,只是爲此活動傳遞參數.... – Selvin

回答

1

我認爲你正在嘗試以編程方式發送電子郵件,而不使用開放的Email Composer。

如果是這樣你可以檢查此link

希望這有助於

+1

很好的發現...但是,您是否在API> 10上測試了此解決方案...如果javax.mail.Transport未使用因爲在API> 10中不允許在UI主線程上執行互聯網操作(所以你需要移動'GMailSender sender = new GMailSender(「[email protected]」,「password」); sender .sendMail(「This is Subject」, 「This is Body」, 「[email protected]」, 「[email protected]」);'AsyncTask – Selvin

+0

我沒有在Api> 10上測試它。感謝您指出, –

-1
package com.contact; 
import java.util.regex.Pattern; 
import android.app.Activity; 
import android.app.Dialog; 
import android.os.Bundle; 
import android.content.Intent; 
import android.graphics.drawable.AnimationDrawable; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 

public class ContactusActivity extends Activity { 
    // Initializing variables 
    EditText inputName; 
    EditText inputEmail; 
    EditText inputphone; 
    EditText inputcomment; 
    ImageView iv; 

    public final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
      "[a-zA-Z0-9+._%-+]{1,256}" + 
      "@" + 
      "[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" + 
      "(" + 
      "." + 
      "[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" + 
      ")+" 
     ); 
    String regexStr = "^[0-9]$"; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     inputName = (EditText) findViewById(R.id.name); 
     inputEmail = (EditText) findViewById(R.id.email); 
     inputphone = (EditText) findViewById(R.id.phone); 
     inputcomment = (EditText) findViewById(R.id.comment); 
     Button sendmail = (Button) findViewById(R.id.sendmail); 
     final ImageView iv= (ImageView) findViewById(R.id.test_image); 
     iv.setBackgroundResource(R.animator.animation); 

     sendmail.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View arg0) { 



       String strname=inputName.getText().toString(); 
       String strmail=inputEmail.getText().toString(); 
       String strphone=inputphone.getText().toString(); 
       String strcmnt=inputcomment.getText().toString(); 


       if(strname.length() == 0 || strmail.length() == 0 
         || strphone.length() == 0 || strcmnt.length() == 0) 
       { 


       Dialog d=new Dialog(ContactusActivity.this); 
       d.setContentView(R.layout.dialog); 
       d.setTitle(""); 
       d.show(); 
        //Toast toast=Toast.makeText(ContactusActivity.this, "please fill all the details.....", 7000); 
        //toast.setGravity(Gravity.CENTER,0,0); 
         // toast.show(); 

       } 
       else 

        if(strcmnt.length() <=20) { 
         Dialog d=new Dialog(ContactusActivity.this); 
          d.setContentView(R.layout.comment); 
          d.setTitle(""); 
          d.show(); 


         } 
        else 

         if(strname.length() <=3) { 
          Dialog d=new Dialog(ContactusActivity.this); 
           d.setContentView(R.layout.name); 
           d.setTitle(""); 
           d.show(); 

         } 
        else 

         if(strphone.length() <10 || strphone.length() >10) { 
          Dialog d=new Dialog(ContactusActivity.this); 
           d.setContentView(R.layout.phone); 
           d.setTitle(""); 
           d.show(); 


          } 


        else{ 


         if(checkEmail(strmail)){ 





       String result=strname +"\n"+ strmail+"\n" + strphone+"\n" + strcmnt; 
       Intent mailintent = new Intent(android.content.Intent.ACTION_SEND); 
       mailintent.setType("text/plain"); 
       mailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"[email protected]" , "[email protected]"}); 
       mailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Please collect my info..."); 

       mailintent.putExtra(android.content.Intent.EXTRA_TEXT, result); 

       startActivity(Intent.createChooser(mailintent, "Sending mail...")); 
       inputName.setText(""); 
       inputEmail.setText(""); 
       inputphone.setText(""); 
       inputcomment.setText(""); 

         } 
         else 
         { 
          Dialog d=new Dialog(ContactusActivity.this); 
          d.setContentView(R.layout.email); 
          d.setTitle(""); 
          d.show(); 

         } 

         } 
      } 

      }); 
     // iv.setOnClickListener(new OnClickListener(){ 

     // public void onClick(View v) { 

       AnimationDrawable anim= (AnimationDrawable) iv.getBackground(); 
       anim. start(); 
      } 

     // }); 

    // } 


    private boolean checkEmail(String strmail) { 
     return EMAIL_ADDRESS_PATTERN.matcher(strmail).matches(); 

} 


} 
+0

http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android –

+0

它幫助我... –

相關問題