Performing authentication

Top  Previous  Next

Some SMTP servers require that you provide username / password authentication to allow you to send email. This is typically used to prevent unauthorized users from using the SMTP server as a relay for sending spam. After establishing a connection with an SMTP server you can login by invoking the login method of an Smtp instance providing your SMTP server username and password as arguments.

 

There are two types of authentication supported by the Smtp class, plain text and CRAM-MD5. Plain text authentication sends your username and password over the network unencrypted whereas CRAM-MD5 encrypts your username and password information prior to sending. Plain text authentication is the default method.

 

Note

 

Neither CRAM-MD5 or plain text authentication is guaranteed to be supported by an SMTP server. Contact your system administrator for details on what level of authentication support your SMTP server provides.  Your username and password on an SMTP server is usually represented by the same username and password used to retrieve email.

 

Example

 

The example below demonstrates login using plain-text authentication.

 

Smtp smtp = new Smtp("smtp.myserver.com");

smtp.connect();

 

// login using default plain text authentication

smtp.login("jsmith","secret");

 

Example

 

The example below demonstrates login using CRAM-MD5 authentication.

 

Smtp smtp = new Smtp("smtp.myserver.com");

smtp.connect();

 

// login using CRAM-MD5 authentication

smtp.login("jsmith","secret",Smtp.AUTH_CRAM_MD5);

 

 





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC