2011-12-17 124 views
0

我想发送一个电子邮件与我的Android应用程序的附件作为附件。我跟着这篇文章(其中有很多):Sending email with attachment through GMailSender?使用GMailSender从Android应用程序发送电子邮件附件失败Transport.send

所以我做了同样的事情,我可以发送电子邮件,但只有没有附件。不幸的是,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对象。

回答

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); 
} 
相关问题