将联系我们页面的邮件发送到特定的电子邮件ID

时间:2012-05-31 11:12:03

标签: android email

我已经尝试过了......但是当我提交表单时,它会转到撰写邮件...我只想通过点击提交按钮发送邮件...请帮助我......

Intent mailintent = new Intent(android.content.Intent.ACTION_SEND);
mailintent.setType("text/plain");
mailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]        
         {"amitk.123@gmail.com" , "ankush.123@gmail.com"});
mailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "info...");         
startActivity(mailintent);

<uses-permission android:name="android.permission.INTERNET" /> 
清单文件中的

2 个答案:

答案 0 :(得分:1)

我认为您正在尝试以编程方式发送电子邮件,而无需打开电子邮件编辑器。

如果是这样,您可以查看link

希望这有帮助

答案 1 :(得分:-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[] {"amitk.cql@gmail.com" , "ankush.cql@gmail.com"});
                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();

}


}