Javamail implements smtp identity authentication

Source: Internet
Author: User
Currently, most smtp servers require identity authentication. If javamail is used to write an email sending and receiving client, how can this function be implemented? The following is a simple column to simulate foxmail's implementation of the authentication function.
Package jmail;
Import javax. mail .*;
Import java. util .*;
Import java. SQL .*;
Import javax. swing .*;
Import java. awt .*;
Public class MailAuthenticator extends Authenticator {
String authenName; // User name
String authenPass; // password
Public MailAuthenticator (String authenName, String authenPass ){
Super ();
This. authenName = authenName;
This. authenPass = authenPass;
}
Public PasswordAuthentication getPasswordAuthentication () {/* if the server requires identity authentication, Sission automatically calls this method.
String temp = null;
If (authenPass. equals ("") | authenPass = null) {/* if the password is blank */
Option op = new Option (null, "authentication", true);/* the pop-up dialog box asking users to enter a password. Option is a custom JDialog that contains a password domain */
Temp = op. showDialog ();/* Option returns the entered password */
AuthenPass = temp;
}
Return new PasswordAuthentication (authenName, authenPass );
}
}
/* The following is the Option class, which is written in jbuilder and does not need to be explained */
Package jmail;
Import java. awt .*;
Import javax. swing .*;
Import com. borland. jbcl. layout .*;
Import java. awt. event .*;
Public class Option extends JDialog {
JPanel panel1 = new JPanel ();
JLabel jLabel1 = new JLabel ();
XYLayout xYLayout1 = new XYLayout ();
JButton jButton1 = new JButton ();
JButton jButton2 = new JButton ();
JPasswordField jPasswordField1 = new JPasswordField ();
JLabel jLabel2 = new JLabel ();
JLabel jLabel3 = new JLabel ();
Icon forget = new ImageIcon (".imagesforget.gif ");
Boolean OK = false;
JLabel jLabel4 = new JLabel ();
JLabel jLabel5 = new JLabel ();
Public Option (Frame frame, String title, boolean modal ){
Super (frame, title, modal );
Try {
JbInit ();
Pack ();
}
Catch (Exception ex ){
Ex. printStackTrace ();
}
}
Public Option (){

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.