简体   繁体   English

如何在未安装电子邮件应用程序的情况下从android应用程序发送电子邮件

[英]How to send Email from android application without installed an email application

I have question. 我有问题。 I've go an E-mail application but when I press the send button I must have at least one E-mail application installed. 我已经使用了一个电子邮件应用程序,但是当我按下发送按钮时,我必须至少安装了一个电子邮件应用程序。 Code: 码:

Java file: Java文件:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    final EditText adress = (EditText) findViewById(R.id.adress);
    final EditText subject = (EditText) findViewById(R.id.subject);
    final EditText message = (EditText) findViewById(R.id.message);
    ImageButton send = (ImageButton) findViewById(R.id.send);

    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_EMAIL  , adress.getText().toString());
            i.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
            i.putExtra(Intent.EXTRA_TEXT   , message.getText().toString());
            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();
            }

            AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
                builder.setIcon(R.drawable.ic_launcher);
                builder.setTitle("Mail");
                builder.setMessage("Mail send sucessfully.");
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MyActivity.this,"Finish.",Toast.LENGTH_SHORT);
                        adress.setText("");
                        subject.setText("");
                        message.setText("");
                    }
                });
        }
    });
}

Please help me. 请帮我。

If the user does not have an email application installed on the phone, you can take the user to the PlayStore and request him to download an email app of their choice (or one that you recommend). 如果用户没有在手机上安装电子邮件应用程序,则可以将用户带到PlayStore并要求他下载他们选择的电子邮件应用程序(或您推荐的电子邮件应用程序)。

The other option is having your own SMTP server using which you can send emails. 另一个选择是拥有自己的SMTP服务器,您可以使用该服务器发送电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM