简体   繁体   English

如何通过在Android应用程序中单击“提交”按钮来发送电子邮件

[英]How to send email by clicking on submit button in Android application

I am creating an android application.in which it has a feedback form. 我正在创建一个android application。在其中它具有反馈表。 Now, as the user clicks on "Submit Comments" button, this should send all the details to my email address, all the details that user entered in the form. 现在,当用户单击“提交评论”按钮时,这会将所有详细信息发送到我的电子邮件地址,用户在表单中输入的所有详细信息。 I've seen so many examples and questions here, but didn't get proper answer. 我在这里看到了很多例子和问题,但没有得到正确的答案。 I don't know how to do it. 我不知道该怎么做。 I am new in android. 我是android新手。 Please help me. 请帮我。

在此处输入图片说明

You can try this on your send button click event: 您可以在发送按钮点击事件中尝试以下操作:

Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"info@xxx.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "title"); 
            i.putExtra(Intent.EXTRA_TEXT, message);//message is your details
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(about.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }

Try this on Submit Button: 在“提交”按钮上尝试以下操作:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
        "mailto","email@email.com", null));
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));

If you don't have a specific recipient - go like this: 如果您没有特定的收件人,请按照以下步骤操作:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
        "mailto",null, null));
Intent email = new Intent(Intent.ACTION_SEND);
              email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
              //email.putExtra(Intent.EXTRA_CC, new String[]{ to});
              //email.putExtra(Intent.EXTRA_BCC, new String[]{to});
              email.putExtra(Intent.EXTRA_SUBJECT, "subject");
              email.putExtra(Intent.EXTRA_TEXT, "message");

              //need this to prompts email client only
              email.setType("message/rfc822");

              startActivity(Intent.createChooser(email, "Choose an Email client :"));

            }

For sending email, you will have to use the inbuilt/installed email clients/apps which have been configured with a correct email account. 要发送电子邮件,您将必须使用已配置了正确电子邮件帐户的内置/已安装电子邮件客户端/应用程序。 There is no API in android for sending mail. android中没有用于发送邮件的API。 Sending receiving emails uses protocols which has been implemented by the email apps. 发送接收电子邮件使用电子邮件应用程序已实现的协议。 Implementing that in your app would make it very complex. 在您的应用中实现该功能将使其变得非常复杂。

Better option for you would be call a web service and pass the data to the server and store it in DB. 更好的选择是调用Web服务,然后将数据传递到服务器并将其存储在DB中。 If you really want to send email, then send the received data at the server as email. 如果您确实要发送电子邮件,则将接收到的数据作为电子邮件发送到服务器。 Depending on the server you are using, you will be able to find connectors for emails. 根据所使用的服务器,您将能够找到电子邮件的连接器。

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

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