3

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..."));

}


}
Rash
  • 876
  • 4
  • 18
  • 39

1 Answers1

1
Edited

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

<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>

http://www.w3schools.com/php/php_mail.asp

http://php.net/manual/en/function.mail.php

Pratik
  • 30,639
  • 18
  • 84
  • 159
  • 2
    you should not send the password to the webservice ... just the username ... then send the email from the web service to the registered address for that user. – Moog Sep 13 '12 at 14:08
  • @Pratik yes I am using web services.I need some code how to use it? – Rash Sep 13 '12 at 14:12
  • @Marlin yes I am using web services.I need some code how to use it? – Rash Sep 13 '12 at 14:24
  • @Rashmi dear I given the example in the answer – Pratik Sep 13 '12 at 14:26
  • @Pratik I want android code how to use web services for sending mail – Rash Sep 13 '12 at 14:26
  • did you call any web service? – Pratik Sep 13 '12 at 14:27
  • then call through the json parser by passing the user email address or check some post to call the service, http://stackoverflow.com/q/6047194/760489, http://stackoverflow.com/q/4410398/760489, http://stackoverflow.com/q/5893892/760489, http://stackoverflow.com/q/7020309/760489 – Pratik Sep 13 '12 at 14:32
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16651/discussion-between-rashmi-and-pratik) – Rash Sep 13 '12 at 14:34
  • I am on chat are you online there? – Pratik Sep 13 '12 at 14:36
  • @Pratik sir I want to retrieved password from MySQL and send it to user email. Where should I start? I can't find any tutorial.. – John Joe Jan 26 '16 at 18:31