2

I am developing an application in which i have to send mail from application. The body and recipient of mail should not be editable. So i configured gmail step by step using this link.

Now the need of application is that, the FROM UserName and password is given by user. It can be of any type as :

abc@gmail.com,
abc@rediffmail.com
abc@yahoomail.com

The email should sent, what ever the user name and password entered by user. I searched about that and got that to send mail from yahoo id application should configure on yahoo smtp server.

But what if user enter other mail id. Is there a common method by which application can send mail? For that what steps i have to perform.

Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95

1 Answers1

0

Try like this,

       address = (EditText) findViewById(R.id.address);
     subject = (EditText) findViewById(R.id.subject);
    emailbody = (EditText) findViewById(R.id.body);
    send = (Button) findViewById(R.id.send);

    send.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sendEmail();
        }
    });
}

public void sendEmail(){

    if(!address.getText().toString().trim().equalsIgnoreCase("")){
      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
      emailIntent.setType("plain/text");
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailbody.getText());
      sendMailDemo.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
    else{
        Toast.makeText(getApplicationContext(), "Please enter an email address..", Toast.LENGTH_LONG).show();
    }
user1835052
  • 455
  • 1
  • 5
  • 11
  • I already tried. But by this code the default composer is accessible. in which mail body and address is editable. My application need is that the body and address should not be editable. – Manoj Fegde Mar 11 '13 at 12:38
  • check out this link.. this may help http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a/2033124#2033124 – user1835052 Mar 11 '13 at 12:45