2012-05-31 45 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

它帮助我... –

相关问题