• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

how to read attachment size using JavaMail?  RSS feed

 
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 .
 
Marshal
Posts: 59745
188
  • 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.
 
Saloon Keeper
Posts: 4691
117
  • 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: 4691
117
  • 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: 4691
117
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!