KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > email > SmtpAuthenticator


1 package email;
2
3 import javax.mail.PasswordAuthentication JavaDoc;
4 import javax.mail.Authenticator JavaDoc;
5
6 /** The class Authenticator represents an object that knows how to obtain authentication
7  * for a network connection.
8  * Applications use this class by creating a subclass, and registering an instance of that
9  * subclass with the system with setDefault(). When authentication is required, the system
10  * will invoke a method on the subclass (like getPasswordAuthentication)
11  *
12  * @author Paloma Trigueros Cabezon
13  * @version 1.0
14  */

15
16 public class SmtpAuthenticator extends javax.mail.Authenticator JavaDoc {
17
18         String JavaDoc pass = "";
19         String JavaDoc login = "";
20
21         public SmtpAuthenticator() {
22                 super();
23         }
24
25         public SmtpAuthenticator(String JavaDoc login, String JavaDoc pass) {
26                 super();
27
28                 this.login = login;
29                 this.pass = pass;
30         }
31
32         public PasswordAuthentication JavaDoc getPasswordAuthentication() {
33                 if (pass.equals(""))
34                         return null;
35                 else
36                         return new PasswordAuthentication JavaDoc(login, pass);
37         }
38
39 }
Popular Tags