【问题标题】:javax.mail.nosuchproviderexception smtpjavax.mail.nosuchprovider 异常 smtp
【发布时间】:2013-10-03 14:39:56
【问题描述】:

我正在使用以下代码在我的 Android 应用程序中发送电子邮件:

    m_properties = new Properties();
    m_properties.put("mail.smtp.host", "smtp.gmail.com");
    m_properties.put("mail.smtp.socketFactory.port", "465");
    m_properties.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
    m_properties.put("mail.smtp.auth", "true");
    m_properties.put("mail.smtp.port", "465");

    m_Session = Session.getDefaultInstance(m_properties,
                    new Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(userName,
                                    passWord);
                        }

                    });

    m_simpleMessage = new MimeMessage(m_Session);

    m_fromAddress = new InternetAddress(userName);
    m_toAddress = new InternetAddress(eRecipient);

    m_simpleMessage.setFrom(m_fromAddress);
    m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
    m_simpleMessage.setSubject(eSubject);
    m_simpleMessage.setContent(eBody, "text/plain");

    Transport.send(m_simpleMessage);

在我混淆我的代码之前,它绝对可以正常工作。然后电子邮件发送失败,抛出错误:javax.mail.nosuchproviderexception smtp

我在我的 proguard.cfg 中尝试了各种设置,例如:-keep class javax.mail.** { *; }

但是没有任何效果。如果我关闭混淆,它会再次正常工作。

任何想法为什么会发生这种情况?

提前致谢。

编辑:我的 Proguard 配置文件

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-verbose


-libraryjars "C:\Program Files\Android\android-sdk\platforms\android-15\android.jar"
-libraryjars "C:\Documents and Settingslibs\commons-io-2.4.jar"
-libraryjars "C:\Documents and Settings\libs\mail.jar"
-libraryjars "C:\Documents and Settingslibs\activation.jar"
-libraryjars "C:\Documents and Settings\libs\additionnal.jar"
-libraryjars "C:\Documents and Settings\libs\dropbox-android-sdk-1.3.1.jar"
-libraryjars "C:\Documents and Settings\libs\microsoft-translator-java-api-0.6.1-jar-with-dependencies.jar"
-libraryjars "C:\Documents and Settings\pingpongboss-StandOut-5c5cbe9\library\bin\standout.jar"
-libraryjars "C:\Documents and Settings\android-uitableview\android-uitableview\bin\br_com_dina_ui.jar"

-dontpreverify


!code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class com.android.vending.licensing.ILicensingService

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}


-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}


-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep public class com.winterwell.jgeoplanet.** {
  public protected *;
}

-keep public class winterwell.jwitter.** {
  public protected *;
}

-keep public class winterwell.json.** {
  public protected *;
}

-keep class com.winterwell.** { *; }

-keep class winterwell.** { *; }

-keep class com.faceture.google.** { *; }
-keep class com.faceture.google.play.** { *; }
-keep class com.faceture.google.play.domain.** { *; }
-keep class com.faceture.http.** { *; }
-keep class com.faceture.rest.** { *; }
-keep class com.faceture.google.gson.** { *; }
-keep class com.google.gson.** { *; }


-dontwarn android.support.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn org.apache.harmony.awt.**
-dontwarn javax.activation.**
-dontwarn com.sun.mail.imap.protocol.**

-keepattributes Signature

-keepattributes *Annotation*


-keep class sun.misc.Unsafe { *; }

-keep class com.google.gson.examples.android.model.** { *; }

由于这些错误,上述警告已被删除:

Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
+ can't find referenced class javax.security.sasl.SaslClient
+ can't find referenced class javax.security.sasl.SaslException
+ can't find referenced class javax.security.auth.callback.NameCallback
+ can't find referenced class javax.security.sasl.RealmCallback

【问题讨论】:

  • 你在做什么来混淆你的代码?
  • 没有什么不寻常的......标准Proguard建议配置的一些补充。我以正常方式引用罐子。你有什么具体的意思吗?谢谢
  • 在我看来,您的更改正在做出导致错误的更改,但不知道它们是什么,我无能为力。
  • 看起来 progard 正在删除您正在使用的一些类您是否尝试使用 -keep public class 像所有导入类一样包含更多类
  • 我已经添加了我的配置 - 我需要弄清楚如何格式化它!谢谢你的帮助。我保留了所有引用上述代码的类,但它仍然失败......

标签: android jakarta-mail


【解决方案1】:

我通过包含下面详述的附加 Proguard 配置解决了这个问题。我从this answer 获得了解决方案,其中包含更多信息。

-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}

-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}

【讨论】:

    【解决方案2】:

    我不知道 Proguard 是什么,但它听起来像是从 mail.jar 中提取类文件并将它们添加到您的 jar 中。不幸的是,它不包括 mail.jar 文件中的配置文件。您需要 mail.jar 文件中 META-INF 中的文件。或者更好的是,不要重新打包 mail.jar,直接使用它。

    【讨论】:

    【解决方案3】:

    这个错误通常是因为“mail.jar”不正确造成的。

    解决方案:

    1] 检查“mail.jar”是否在您的类路径中。

    2] 如果它在类路径中,检查“mail.jar”的最新版本,然后 将其包含在您的类路径中。

    您可以查看和下载最新版本,

    http://www.oracle.com/technetwork/java/index-138643.html

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 2012-12-13
      • 2015-02-10
      • 2015-11-20
      • 2023-03-10
      • 2012-11-10
      相关资源
      最近更新 更多