[英]How to sending email from android like “mailto:” in PHP?
has everyone know how to sending an email from android device like mailto: in PHP?? 有没有人知道如何从Android设备(例如mailto :)在PHP中发送电子邮件? i really need that for my lockscreen application.. it will send a email (email must be registered before) to the client when his/her forgot his/her password.
我确实需要我的锁屏应用程序..当他/她忘记密码时,它将向客户发送一封电子邮件(必须先注册电子邮件)。 what should i do??
我该怎么办?? any idea??
任何想法?? thanks..
谢谢..
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();
}*/
}
}
and on the mainForm : 并在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;
}
}
}
you can do by this way :: 您可以通过这种方式进行::
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.