This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 63381
205
  • 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: 5282
143
  • 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: 5282
143
  • 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: 5282
143
  • 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.
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!