【问题标题】:Send email with attachment from android app using GMailSender fails at Transport.send使用 GMailSender 从 Android 应用程序发送带有附件的电子邮件在 Transport.send 失败
【发布时间】:2011-12-17 23:15:32
【问题描述】:

我正在尝试从我的 Android 应用程序发送一封带有图像作为附件的电子邮件。我关注了这篇文章(以及许多其他帖子):Sending email with attachment through GMailSender?

所以我做了同样的事情,我可以发送电子邮件,但只能不带附件。不幸的是, Transport.send 似乎失败了。过了一会儿,它显示:

D/SntpClient( 61): request time failed: java.net.SocketException: Address family not supported by protocol

我尝试以不同的方式创建 File 对象(streamUri 我相信是正确的):

Uri streamUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); 
File f = new File(streamUri.toString()); //I get an error if I pass only streamUri as parameter

还有

File f = new File(streamUri.getEncodedPath());

但我明白了:

(  418): IOException while sending message
(  418): javax.mail.MessagingException: IOException while sending message;
(  418):   nested exception is:
(  418):    java.io.FileNotFoundException: /media/external/images/media/2 (No such file or directory)

所以我怀疑我可能错误地创建了 File 对象。

【问题讨论】:

    标签: java android gmail email-attachments jakarta-mail


    【解决方案1】:

    路径不正确,这解决了问题:

    public String getRealPathFromURI(Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 2013-08-26
      • 2016-02-18
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多