0

I have a simple contact form app and what I want to accomplish is once the form is filled out, I want the info sent directly to my gmail after pressing the send button. I do not want the "Complete action using" to pop up. Just sent directly to my gmail. I am currently using an intent to make the info to be sent. Is there some other type of method I could use to have the info directly sent to my gmail?

Here is my MainActivity.java file:

package com.qnutapps.contactform1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity  extends Activity implements OnClickListener{
/** Called when the activity is first created. */

    EditText etname, etphone, etemail, etadd;

    Button send;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);    

    etname = (EditText) findViewById (R.id.etName);

    etphone = (EditText) findViewById (R.id.etPhone);

    etemail = (EditText) findViewById (R.id.etEmail);       

    etadd = (EditText) findViewById (R.id.etAdd);

    send = (Button) findViewById (R.id.send);      

    send.setOnClickListener(this);
  }

public void onClick(View Arg0) {


         //if(etname.getText().toString().length()==0)  
         //{           
          //etname.setError( "Please Enter Your Name" );  
         //}  
         //else if(etphone.getText().toString().length()==0)  
         //{           
          //etphone.setError( "Please Enter Your Phone #" ); 
         //}
         //else if(etemail.getText().toString().length()==0)  
         //{           
          //etemail.setError( "Please Enter Your E-mail" );
         //}
         //else if(etadd.getText().toString().length()==0)  
         //{           
          //etadd.setError( "Vul uw bericht in" );  
         //}
         //else if(subject.getSelectedItemPosition()==0)  
         //{           
          //Toast.makeText(MainActivity.this,"Please select the Subject",Toast.LENGTH_SHORT).show(); 
         //}
         //else
         //{             
            Toast.makeText(getApplicationContext(), "Sending E-Mail", Toast.LENGTH_SHORT).show(); //Sends message after button is clicked

            StringBuilder body = new StringBuilder();

            body.append("Name: "+etname.getText().toString());

            body.append("\nPhone: "+etphone.getText().toString());

            body.append("\nEmail: "+etemail.getText().toString());

            body.append("\nAdditional Information: "+etadd.getText().toString());



            Intent emailIntent = new Intent(Intent.ACTION_SEND); 

            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"marketing.otwist@gmail.com"});           

            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Customer Details");

            emailIntent.putExtra(Intent.EXTRA_TEXT, body.toString());

            emailIntent.setType("message/rfc822");  //can also use "message/rfc822"

            startActivity(emailIntent);  


         }         
}
//}
OliverTwist
  • 43
  • 2
  • 8
  • see this http://stackoverflow.com/questions/46663/how-to-send-an-email-by-java-application-using-gmail-yahoo-hotmail – Goran Horia Mihail Dec 14 '13 at 14:56
  • As @madlymad said, either you use the JavaMail API to send the message directly or you need to let Android handle the request. with `startActivity(Intent.createChooser(emailIntent, "Choose an Email client :"));` the little message Box will pop up where you can choose which email client you want to use. You are not supposed to make any assumptions on what emailclients are available on your phone nor should you try making the choice for the user ... at least that's the idea behind it. So you need the box. – GameDroids Dec 14 '13 at 15:02
  • @GameDroids Thanks. It's not like I'm trying to make a choice for the user. All I want is the user to fill out the form and press the send button and bam! straight to my email. I'm just a beginner so I am still trying to understand this new crazy language – OliverTwist Dec 14 '13 at 15:06

2 Answers2

0

You can use JavaMail API but its not that easy.

Check that answer: Sending Email in Android using JavaMail API without using the default/built-in app

Community
  • 1
  • 1
madlymad
  • 6,367
  • 6
  • 37
  • 68
  • Yeah I can see that it's not that easy and I'm only a beginner. I'll give it a try. Thanks – OliverTwist Dec 14 '13 at 15:01
  • Instead you can try using post to google spreadsheet and not email. Like this guy here: http://stackoverflow.com/questions/6174962/using-android-to-submit-to-a-google-spreadsheet-form – madlymad Dec 14 '13 at 15:15
0

Well using HTML u can send it quite easily. mailto : "email address".

I don't know u can use HTML over here or not