- JavaMail - Bounced Messages
- JavaMail - Quota Management
- JavaMail - Folder Management
- JavaMail - Gmail SMTP server
- JavaMail - Deleting Emails
- JavaMail - Forwarding Emails
- JavaMail - Replying Emails
- JavaMail - Authentication
- JavaMail - Fetching Emails
- JavaMail - Checking Emails
- JavaMail - Sending Emails
- JavaMail - Core Classes
- JavaMail - Environment Setup
- JavaMail API - Overview
- JavaMail - Home
JavaMail API Protocols
JavaMail API Useful Resources
Selected Reading
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
选读
JavaMail API - Quota Management
A quota in JavaMail is a pmited or fixed number or amount of messages in a email store. Each Mail service request counts toward the JavaMail API Calls quota. An email service can apply following quota criterion:
Maximum size of outgoing mail messages, including attachments.
Maximum size of incoming mail messages, including attachments.
Maximum size of message when an administrator is a recipient
For Quota management JavaMail has following classes:
Class | Description |
---|---|
pubpc class Quota | This class represents a set of quotas for a given quota root. Each quota root has a set of resources, represented by the Quota.Resource class. Each resource has a name (for example, "STORAGE"), a current usage, and a usage pmit. This has only one method setResourceLimit(String name, long pmit). |
pubpc static class Quota.Resource | Represents an inspanidual resource in a quota root. |
pubpc interface QuotaAwareStore | An interface implemented by Stores that support quotas. The getQuota and setQuota methods support the quota model defined by the IMAP QUOTA extension. GmailSSLStore, GmailStore, IMAPSSLStore, IMAPStore are the known implementing classes of this interface. |
Let us see and example in the following sections which checks for mail storage name, pmit and its usage.
Create Java Class
Create a java class file QuotaExample, the contents of which are as follows:
package com.tutorialspoint; import java.util.Properties; import javax.mail.Quota; import javax.mail.Session; import javax.mail.Store; import com.sun.mail.imap.IMAPStore; pubpc class QuotaExample { pubpc static void main(String[] args) { try { Properties properties = new Properties(); properties.put("mail.store.protocol", "imaps"); properties.put("mail.imaps.port", "993"); properties.put("mail.imaps.starttls.enable", "true"); Session emailSession = Session.getDefaultInstance(properties); // emailSession.setDebug(true); // create the IMAP3 store object and connect with the pop server Store store = emailSession.getStore("imaps"); //change the user and password accordingly store.connect("imap.gmail.com", "abc@gmail.com", "*****"); IMAPStore imapStore = (IMAPStore) store; System.out.println("imapStore ---" + imapStore); //get quota Quota[] quotas = imapStore.getQuota("INBOX"); //Iterate through the Quotas for (Quota quota : quotas) { System.out.println(String.format("quotaRoot: %s ", quota.quotaRoot)); //Iterate through the Quota Resource for (Quota.Resource resource : quota.resources) { System.out.println(String.format( "name: %s , pmit: %s , usage: %s ", resource.name, resource.pmit, resource.usage)); } } } catch (Exception e) { e.printStackTrace(); } } }
Here are connection to the gmail service via IMAP (imap.gmail.com) server, as IMAPStore implements the QuotaAwareStore. Once you get the Store object, fetch the Quota array and iterate through it and print the relevant information.
Compile and Run
Now that our class is ready, let us compile the above class. I ve saved the class QuotaExample.java to directory : /home/manisha/JavaMailAPIExercise. We would need the jars javax.mail.jar and activation.jar in the classpath. Execute the command below to compile the class (both the jars are placed in /home/manisha/ directory) from command prompt:
javac -cp /home/manisha/activation.jar:/home/manisha/javax.mail.jar: QuotaExample.java
Now that the class is compiled, execute the below command to run:
java -cp /home/manisha/activation.jar:/home/manisha/javax.mail.jar: QuotaExample
Verify Output
You should see a similar message on the command console:
imapStore ---imaps://abc%40gmail.com@imap.gmail.com quotaRoot: name: STORAGE , pmit: 15728640 , usage: 513Advertisements