dcsimg
Authentication with Javamail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, October 2, 2002 12:54 AM

My proxy server need authentication to access. How do i pass my username and password to the proxy server using javamail?

Re: Authentication with Javamail

Posted By:   Aleksei_Valikov  
Posted On:   Thursday, January 30, 2003 04:58 AM

I am using an inner class extending Authenticator to do this:
public class Mailer
{
/** Username to use for authentication. */
protected String username;

/** Password to use for authentication. */
protected String password;

/**
* Authenticator to be used with servers requiring authentication. If server
* does not require authentication, this object will be ignored, but it is,
* nevertheless, required.
*/
protected Authenticator authenticator = new BasicAuthenticator();

// ...

public void sendMessage(final String from, final String to,
final String subject, final String text) throws MessagingException
{
// Create a new session
final Session session = Session.getDefaultInstance(properties, authenticator);
// ...
}

/**
* Authenticates component using configured username and password.
*/
public class BasicAuthenticator extends Authenticator
{
/**
* Password authentication, returning username and password specified
* in the implementation.
*/
protected PasswordAuthentication passwordAuthentication = new PasswordAuthentication(username, password);

/**
* Returns object performing password-based authentication.
* @return Password authentication object.
*/
protected PasswordAuthentication getPasswordAuthentication()
{
return passwordAuthentication;
}
}
}

However, not 100% sure that this will work everywhere.
About | Sitemap | Contact