简体   繁体   English

如何判断我的电子邮件是否已发送?

[英]How can I tell if my email has been sent?

I'm using the following code to send an email in my app. 我正在使用以下代码在我的应用中发送电子邮件。

public void sendEmail() {
    emailSent = 1;
    String to = toEmail.getText().toString();
    String subject = getUser() + " - User Feedback";
    String message = bodyTxt;

    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, message);

    email.setType("message/rfc822");
    try {
        startActivity(Intent.createChooser(email, "Send Email..."));
    } catch (android.content.ActivityNotFoundException ex) {
        String msg = ex.getMessage().toString();
        emailSent = 2;
        Toast.makeText(this, "There was a problem sending this email, please try again.", Toast.LENGTH_SHORT).show();
    } 
}

The email.setType() presents a screen offering options for which method to send the message including email. email.setType()显示一个屏幕,其中提供了用于选择发送电子邮件(包括电子邮件)的方法的选项。 This works fine if the user selects email as a copy of the email comes up and the user can then send it. 如果用户选择电子邮件作为电子邮件副本出现,然后用户可以发送它,则此方法很好。 However, if the user doesn't do anything and simply uses the back space it returns to the app and assumes the email has been sent. 但是,如果用户什么也不做,仅使用退格键,它将返回到应用程序并假定电子邮件已发送。 How can I test for the user not sending the email? 如何测试用户未发送电子邮件?

You could startActivityForResult() and listen for a RESULT_OK in onActivityResults . 您可以startActivityForResult()并在onActivityResults监听RESULT_OK But there is no framework requirement that forces the email app to setResult appropriately. 但是,没有框架要求可以强制电子邮件应用适当地设置setResult So your mileage may vary based on the email client app. 因此,您的里程可能会因电子邮件客户端应用程序而异。

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

相关问题 Android-如何确定我的密钥已对apk进行了签名 - Android - How can I tell that an apk has been signed with my key 如何确定Play商店中的APK更新时间? - How can I tell when my apk has been updated in the Play store? 如何判断我的 textview 是否已被省略? - How do I tell if my textview has been ellipsized? 如何举杯说“电子邮件已成功发送”的消息? - How to toast a message said that the “email message has been sent successfully”? Android:如何确认电子邮件已成功发送 - Android: How to confirm that email has been sent successfully 通知应用程序(如果已在Android中发送电子邮件) - Notify application if email has been sent in Android 如何查看来自我的Android应用程序的已发送电子邮件? 还是打算完成(无论发送了什么电子邮件)? - How can I check sent emails from my Android application? Or intent upon completion (regardless of email sent)? 你怎么知道什么时候已经绘制了布局? - How can you tell when a layout has been drawn? 如何查找短信是否已在android中发送? - How do i find if sms has been sent in android? android Action_send intent如何知道一旦发送电子邮件以关闭当前活动? - android Action_send intent how to know once an email has been sent to close the current activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM