Category: 20. Java Mail
-
SMTP Servers
SMTP is an acronym for Simple Mail Transfer Protocol. It is an Internet standard for electronic mail (e-mail) transmission across Internet Protocol (IP) networks. SMTP uses TCP port 25. SMTP connections secured by SSL are known by the shorthand SMTPS, though SMTPS is not a protocol in its own right. JavaMail API has package com.sun.mail.smtp which act as…
-
Bounced Messages
A message can be bounced for several reasons. This problem is discussed in depth at rfc1211. Only a server can determine the existence of a particular mailbox or user name. When the server detects an error, it will return a message indicating the reason for the failure to the sender of the original message. There are…
-
Quota Management
A quota in JavaMail is a limited 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: For Quota management JavaMail has following classes: Class Description public class Quota This class represents a set of…
-
Gmail SMPT Server
In all previous chapters we used JangoSMPT server to send emails. In this chapter we will learn about SMPT server provided by Gmail. Gmail (among others) offers use of their public SMTP server free of charge. Gmail SMTP server details can be found here. As you can see in the details, we can use either TLS…
-
Deleting Emails
In this chapter we will see how to delete an email using JavaMail API. Deleting messages involves working with the Flags associated with the messages. There are different flags for different states, some system-defined and some user-defined. The predefined flags are defined in the inner class Flags.Flag and are listed below: POP protocol supports only…
-
Forwarding Emails
In this chapter we will see how to forward an email using JavaMail API. Basic steps followed in the program below are: Here we have used JangoSMPT server via which emails are sent to our destination email address. The setup is explained in the Environment Setup chapter. Create Java Class Create a java class file ForwardEmail, the contents…
-
Replying Emails
In this chapter we will see how to reply to an email using JavaMail API. Basic steps followed in the program below are: Here we have used JangoSMPT server via which emails are sent to our destination email address. The setup is explained in the Environment Setup chapter. Create Java Class Create a java class file ReplyToEmail, the…
-
Authentication
In the previous chapters Checking Emails and Fetching Emails, we passed authorization credentials (user ad password) along with host, when connecting to store of your mailbox. Instead we can configure the Properties to have the host, and tell the Session about your custom Authenticator instance. This is shown in the example below: Create Java Class We will modify our CheckingMails.java…
-
Fetching Emails
In the previous chapter we learnt how to check emails. Now let us see how to fetch each email and read its content. Let us write a Java class FetchingEmail which will read following types of emails: Basic steps followed in the code are as below: Create Java Class Create a java class file FetchingEmail, contents of which…
-
Checking Emails
There are two aspects to which needs to understood before proceeding with this chapter. They are Check and Fetch. To check or fetch an email using JavaMail API, we would need POP or IMAP servers. To check and fetch the emails, Folder and Store classes are needed. Here we have used GMAIL’s POP3 server (pop.gmail.com). In this chapter…