首页 > 解决方案 > 使用 jar 库的 android 应用程序中的电子邮件传递问题

问题描述

我正在开发一个使用 jar 库发送电子邮件的应用程序。我正在使用自定义电子邮件帐户从 android 应用程序发送电子邮件。以下是发送者活动的代码

private String mailhost = "us2.smtp.mailhostbox.com";
public GMailSender(String user, String password) {
    this.user = user;
    this.password = password;

    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.host", mailhost);
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.socketFactory.port", "587");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");
    props.setProperty("mail.smtp.quitwait", "false");
    session = Session.getDefaultInstance(props, this);
}

以下代码用于设置发件人和收件人

final ProgressDialog pd = ProgressDialog.show(MessageActivity.this,"Sending...", "Please Wait...",true);
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            GMailSender sender = new GMailSender("apps@softglobe.net", "XXXXXX");
                            //sender.addAttachment(Environment.getExternalStorageDirectory().getPath()+"/image.jpg");
                            sender.sendMail("New Message from Arsod Classes App", "New Message from Arsod Classes App\nName: " + nm + "\nEmail: " + em + "\nMessage: " + msg,
                                    "apps@softglobe.net", "softglobe.technologies@gmail.com");

                            MessageActivity.this.runOnUiThread(new Runnable() {
                                public void run() {
                                    pd.dismiss();
                                    Toast.makeText(getApplicationContext(), "Mail Sent successfully!", Toast.LENGTH_LONG).show();
                                }
                            });
                        } catch (Exception e) {
                            Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
                        }
                    }
                }).start();

当我尝试使用上述代码发送电子邮件时,Toast出现“电子邮件已发送”,但我没有在收件人一侧接收。同样,当我尝试使用php网站和phpmailer库发送具有相同凭据的电子邮件时,电子邮件发送成功。可能是什么问题?请帮忙。我花了很多时间,但没有找到任何解决方案。我正在使用 google 提供的 jar 库作为activation.jar,additional.jarmail.jar.

标签: androidemail

解决方案


推荐阅读