如何从android发送电子邮件,如"mailto; "在PHP中


How to sending email from android like "mailto:" in PHP?

是否每个人都知道如何从android设备发送电子邮件,如mailto:在PHP??我的锁屏应用真的需要这个。当客户忘记自己的密码时,会发送邮件给客户(邮件必须是注册过的)。我该怎么办?任何想法?谢谢. .

package com.application.outgoingemail;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class EmailService extends Service { 
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        //Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onStart(Intent intent, int startid) {
        //Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
        sendEmail();
    }
    @Override
    public void onDestroy() {

    }
    public void sendEmail()
    {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"myEmail@example.com"});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT   , "body of email");
        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(EmailService.this,ex.getMessage(), Toast.LENGTH_SHORT).show();
            Toast.makeText(EmailService.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }
        /*try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (Exception ex) {
            Toast.makeText(EmailService.this,ex.getMessage(), 10).show();
            //Toast.makeText(EmailService.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }*/
    }
}

和在mainForm上:

package com.application.outgoingemail;
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.Toast;
public class main extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    Button Button1,Button2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button1=(Button)findViewById(R.id.button1);
        Button1.setOnClickListener(this);
        Button2=(Button)findViewById(R.id.button2);
        Button2.setOnClickListener(this);
    }
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.button1:
                startService(new Intent(main.this, EmailService.class));
            break;
        case R.id.button2:
                stopService(new Intent(main.this, EmailService.class));
            break;
        default:
            break;
        }
    }
}

你可以这样做::

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}