发送带有Gmail问题的电子邮件

时间:2018-06-29 07:35:20

标签: android email gmail

当我发送邮件时,出现此错误。我想从程序中发送邮件。我该怎么做 ?我得到这个参考:

https://www.oodlestechnologies.com/blogs/Send-Mail-in-Android-without-Using-Intent

我的错是什么?因此,如果有任何示例,我也可以更改代码。

LogCat,

 FATAL EXCEPTION: Thread-2
        Process: com.com.aa.aa., PID: 29810
        java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/datatransfer/Transferable;
        at com.com.aa.aa..main.GMailSender.sendMail(GMailSender.java:109)
        at com.com.aa.aa..main.Fonksiyonlar$1.run(Fonksiyonlar.java:49)
        at java.lang.Thread.run(Thread.java:764)
        Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.datatransfer.Transferable" on path: DexPathList[[zip file "/data/app/com.com.aa.aa.-tkR53Nh-qW6albGeAiUVLw==/base.apk"],nativeLibraryDirectories=[/data/app/com.com.aa.aa.-tkR53Nh-qW6albGeAiUVLw==/lib/arm, /data/app/com.com.aa.aa.-tkR53Nh-qW6albGeAiUVLw==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.com.aa.aa..main.GMailSender.sendMail(GMailSender.java:109) 
        at com.com.aa.aa..main.Fonksiyonlar$1.run(Fonksiyonlar.java:49) 
        at java.lang.Thread.run(Thread.java:764) 

我的sendMail函数是;

public synchronized void sendMail(String subject, String body,

                                      String sender, String recipients) throws Exception {

        try {

            MimeMessage message = new MimeMessage(session);

            DataHandler handler = new DataHandler(new ByteArrayDataSource(

                    body.getBytes(), "text/plain"));

            message.setSender(new InternetAddress(sender));

            message.setSubject(subject);

            message.setDataHandler(handler);

            BodyPart messageBodyPart = new MimeBodyPart();

            messageBodyPart.setText(body);

            _multipart.addBodyPart(messageBodyPart);


            // Put parts in message

            message.setContent(_multipart);

            if (recipients.indexOf(',') > 0)

                message.setRecipients(Message.RecipientType.TO,

                        InternetAddress.parse(recipients));

            else

                message.setRecipient(Message.RecipientType.TO,

                        new InternetAddress(recipients));

            Transport.send(message);

        } catch (Exception e) {


        }

    }

1 个答案:

答案 0 :(得分:0)

也许是重复的:JavaMail: Java.awt.datatransfer.Transferable doesn't exist

我认为您忘了添加文章https://code.google.com/archive/p/javamail-android/downloads

中提到的第三个库