发送单个电子邮件ID的电子邮件,而不使用Android中的Intent

时间:2014-05-04 02:10:19

标签: android email smtp gmail

我正在开发一个应用程序,它有一个表单来发送没有内置应用程序的电子邮件。我看过很多电子邮件发送的例子。在所有示例中,它都是针对如此多的电子邮件ID。这意味着我们可以一次向多个人发送电子邮件。但我想只向一个人发送电子邮件。我正在学习本教程。请让我知道在哪里以及我应该更改代码。

http://javapapers.com/android/android-email-app-with-gmail-smtp-using-javamail/

ToEmail 框中的本教程中,我们可以添加多个电子邮件ID。但我只想添加一个电子邮件ID。请帮助我在哪里更改此内容。这是我从本教程编辑的代码..plzzz帮助。

import java.util.Arrays;
import java.util.List;
import javax.security.auth.Subject;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class Contact extends Activity implements OnClickListener, OnItemSelectedListener
{

    Button submit1,clear;
    EditText et1,et2,et3;
    Spinner spin;

    String[] selction = { "I want to request a mobile feature", 
            "I want to tell about something that I like",
            "I want to tell you about something that I do not like",
            "I have general comments", 
            "I want to contact the office",
            "I want to suggest an improvement in the church premise"};  


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact);

        Spinner spin=(Spinner)findViewById(R.id.spinner1);
        spin.setOnItemSelectedListener(this);

        @SuppressWarnings({ "unchecked", "rawtypes" })
        ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,selction);  
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  


        //Setting the ArrayAdapter data on the Spinner  
        spin.setAdapter(aa);  


//--------------------Submit_Button_Start-----------------------------------------------------------        

        final Button submit1=(Button)findViewById(R.id.button1);
        submit1.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v)
            {
                Log.i("SendMailActivity", "Send Button Clicked.");
                String fromEmail ="user@gmail.com";
                String fromPassword="password";
                String toEmails="anything@gmail.com";
                //List<String> toEmailList = Arrays.asList(toEmails.split("\\s*,\\s*"));
                //Log.i("SendMailActivity", "To List: " + toEmailList);

                String emailBody = ((TextView) findViewById(R.id.editText1)).getText().toString();
                new SendMailTask(Contact.this).execute(fromEmail,fromPassword, toEmails, emailBody);
            }
        });

//--------------------Submit_Button_End-----------------------------------------------------------      


        clear=(Button)findViewById(R.id.button2);
        clear.setOnClickListener(this);

        et1=(EditText)findViewById(R.id.editText1);
        et2=(EditText)findViewById(R.id.editText2);
        et3=(EditText)findViewById(R.id.editText3);

        /*ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this,R.array.question,android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);*/
    }

    public boolean onCactivity_list_itemreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.contact, menu);
        return true;
    }
/*
    @Override
    public void onItemSelected(AdapterView<?> parent, View v, int position,long id) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }
*/
    @Override
    public void onClick(View v1)
    {

        if(v1==clear)
        {
            et1.setText("");
            et2.setText("");
            et3.setText("");
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        /*
        new AlertDialog.Builder(Contact1.this)
    .setMessage("Your requested has been Accepted\nThank You")
    .setCancelable(false)
    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) 
    {
      dialog.cancel();
        }
    })  
        .show();*/
    }

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

}

1 个答案:

答案 0 :(得分:0)

看起来你应该只用一个项目来构建一个列表。类似的东西:

...
List<String> toEmailList = new ArrayList<String>();
toEmailList.add("anything@gmail.com");
...