Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read attachment size using JavaMail?  RSS feed

 
Pooja Patel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a code to read email with particular subject name and, if the mail contains any attachment i want to read the size of attachment. Can you please suggest the needful .
 
Campbell Ritchie
Marshal
Posts: 56193
171
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Divide and rule. Start off with the text of an email from somewhere and see how attachments are signalled, and how to identify their start and end.
 
Tim Moores
Saloon Keeper
Posts: 3953
94
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaMail FAQ covers a lot of that, particularly the answers to "How do I tell if a message has attachments?", "How do I find the attachments in a message?" and "How do I read a message with an attachment and save the attachment?".

Any object that implements the javax.mail.Part interface (like javax.mail.BodyPart) has a getSize method.
 
Pooja Patel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks for the reply .

I am new to java, so it is very difficult to understand a lot.
I am getting count of unreadmails, but unable to fetch the attachment.

I have assigned mail to Message , after that i am unable to convert into Bodypart object to get the size value or the count of attachment. Can you please suggest more.

Thanks in Advance
 
Tim Moores
Saloon Keeper
Posts: 3953
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "unable to fetch and "unable to convert" mean? Post the code you're using, describe what you think it should be doing, and what it does instead.
 
Pooja Patel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


By using above logic, I am able to print the emailcount. Post this i want to check how many mails have attachment and if the attachment is present,then size of the attachment to read.

Thanks in Advance
 
Tim Moores
Saloon Keeper
Posts: 3953
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to check how many mails have attachment

The FAQ entry "How do I tell if a message has attachments?" I pointed you to shows you how to determine whether a Message has an attachment.

if the attachment is present,then size of the attachment to read.

That's what the FAQ entry "How do I read a message with an attachment and save the attachment?" is about.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!