I have created login demo.I am parsing username and password using JSON parser which is connected with PHP code.I have also done code for forgot password.But I am unable to get any mail.Why?I have created one Forgot password activity in that one textfield for entering email id and when I hit submit button,mail should go with password to my inbox.How to do it?anyone please help me?
Here is my code for Forgot Password:
package com.Login;
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.TextView;
public class ForgotPassActivity extends Activity {
EditText address, subject, emailbody, et_email;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.forgot_password);
TextView textv = (TextView) findViewById(R.id.lbl_loginhere);
et_email = (EditText) findViewById(R.id.et_email);
textv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ForgotPassActivity.this.finish();
Intent intent = new Intent();
intent.setClass(v.getContext(), LoginActivity.class);
startActivity(intent);
}
//Code For Sending mail
});
Button b1 = (Button) findViewById(R.id.submitButton);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
sendEmail();
}
});
}
public void sendEmail(){
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"testmail@testmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailbody.getText());
ForgotPassActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
}
If you’re using any web service the better way is call the web service by passing the user email address and search in your database and fetch the record. For secure way passing data create the Post service and from your service like php or any another technology send the mail to the incoming email with it’s password.
Updated
you can use this function from your service mail() see for more info from the links and here is simple snippet of code
http://www.w3schools.com/php/php_mail.asp
http://php.net/manual/en/function.mail.php