0

I am currently working on an Android application which has an "ask a question form", where user type a question and send it to predetermined email address. I would like to know how I can allow the application to capture what the user has input and send the input directly to a predeteremined email using button, either without bringing the user to the email app page, or capture all user input and send it to the built in email intent. I have seen many question related to my question but I just want to confirm that if I follow this Sending Email in Android using JavaMail API without using the default/built-in app

answer, would it allow me to capture user input and send it to pre determined email address?

Following is the code I tried

public void onClick(View v) {
    // TODO Auto-generated method stub
    convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
    String[] to = {"[email protected]"};

    String message[] = {name} ;
    String message2 [] = {mobile} ;
    String message3 [] = {email2} ;
    String message4 [] = {question} ;


    Intent Emailintent = new Intent(android.content.Intent.ACTION_SEND) ;
    Emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, to);

    Emailintent.setType("plain/text");
    Emailintent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    Emailintent.putExtra(android.content.Intent.EXTRA_TEXT, message2);
    Emailintent.putExtra(android.content.Intent.EXTRA_TEXT, message3);
    Emailintent.putExtra(android.content.Intent.EXTRA_TEXT, message4);
    startActivity(Emailintent);
}
private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() {
    // TODO Auto-generated method stub
    email2= youremail.getText().toString();
    mobile = yourmobile.getText().toString();
    name = yourname.getText().toString();
    question = yourquestion.getText().toString();


}
Community
  • 1
  • 1

3 Answers3

1

Try doing this:

EditText ed=(EditText) findViewById(R.id.edittext1);

And when user edits the edit text, he presses a button:

button.setOnClickListener(this);

Implement the onclick listener and add unimplemented methods and inside the onclicklistener, do the following:

String emailaddress="[email protected]";
String subject="Subject";
String message=ed.getText().toString();
Intent email = new Intent(android.content.Intent.ACTION_SEND);
email.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
email.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
email.setType("plain/text");
email.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(email);
Adnan Zahid
  • 573
  • 1
  • 10
  • 38
1

Try this, I think this is what you expecting, it will post all the details to your email box,

Step 1:

Call this convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() before sending your email.

(or)

Step 2: Use this Code

In OnClick method

        convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();

        String body = "Name:"+ name+"\n Mobile"+ mobile+"\n Emailto"+email2+"\nQuestion"+ question;
        Intent emailtosend = new Intent(Intent.ACTION_SEND);
        emailtosend.putExtra(Intent.EXTRA_EMAIL, new String[]{ to}); 
        emailtosend.putExtra(Intent.EXTRA_TEXT, body);

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

        startActivity(Intent.createChooser(emailtosend, "Select email application"));    

Hope it helps

vinothp
  • 9,939
  • 19
  • 61
  • 103
  • Thank for your reply, but this code does not capture user input from my application's question form, it captures predetermined subject and body and put it into the builtin email's subject and body, I want to put user's input in the body. Can you help me with how to do that, look at the code I tried – user1219484 Aug 02 '12 at 13:09
  • no this wont capture you have to assign it to the form see my edited answer – vinothp Aug 02 '12 at 13:16
1

Follow the steps in the link you gave, it seems to work. Keep in mind that, there is hard-coded password in the code.

Community
  • 1
  • 1
vipsy
  • 427
  • 3
  • 9