know that in the development of javamail we must verify the authorization, the authorization to check the purpose is to prevent other people arbitrary hair mail, reduce the production of spam.We can validate the session object when we get it. There are two methods in the Session object:
Getdefaultinstance (Prop,authenticator),
GetInstance (Prop,authenticator),
Both of these methods have a common parameter authenticator, which is a authenticator object. The authenticator object is
();
Prop.setproperty ("Mail.host", "smtp.163.com")//Set server host name
prop.setproperty ("Mail.smtp.auth", "true");/setting requires authentication
Where authenticator is an interface representing the authenticator, that is, verifying the identity of the client. We need to implement this interface on our own, and we need to use our account and password to implement this interface.
Authenticator auth = new Authenticator () {public
passwordauthenticati
, and "*" indicates all computers. As you can see from the front of the item format, this is a global-like option that indicates that the options below indent apply to this setting, and you can specify that a computer replaces the * number so that the following options are only available for that machine.Forwardagent No"Forwardagent" Sets whether the connection is forwarded to the remote computer through the authentication agent (if present).ForwardX11 No"ForwardX11" sets whether the X11 connect
class is an abstract class, but the inheritance class of this class is not provided in the API documentation. OK. Let's inherit it by ourselves.
Static class smtpauth extends javax. Mail. authenticator {Private string user, password;
Public void getuserinfo (string getuser, string GetPassword ){User = getuser;Password = GetPassword;}Protected javax. Mail. passwordauthentication getpasswordauthentication (){Return new javax. Mail.
Debian-the Linux Release Technology-Debian information of SSH under Debian. The following is a detailed description. SSH Installation
Apt-get install openssh-server
Apt-get install ssh
SSH Configuration
OpenSSH configuration is concentrated in the/etc/ssh/ssh_config file.
Edit the "ssh_config" file (vi/etc/ssh/ssh_config) and add or change the following parameters:
# Site-wide defaults for various options
Host *
ForwardAgent no
ForwardX11 no
RhostsAuthentication no
RhostsRSAAuthentication no
pair in xshell in tools. The steps are not detailed. Copy the public key to the Pb1 root directory. mkdir ~ in authorized_keys under ssh ~ /. Ssh vi ~ /. Ssh/authorized_keys ssh-dss logs/SafTyWZgH41gP9U/sfqns1_n4xrdohnda0cgzo/0y0OLP + BoG/samples + samples/logs/h4lzV4q9pqN3FkyS/logs D + iEfw5qawYDG8H1XD2/release + 3r7 + IU3Yvvya0P24TZPNhuiwIlU/w ==## this is generated by xshell and copied 2. edit/etc/ssh/sshd_config in Pb1 and change the port to 28888. Disable password authentication in code au
hostbasedauthentication.However,/ETC/HOSTS.EQUIV and/ETC/SHOSTS.EQUIV will still be used. It is recommended to set the default value "Yes".# Don ' t read the user ' s ~/.rhosts and ~/.shosts files#IgnoreRhosts YesWhether to ignore. rhosts and. shosts files during rhostsrsaauthentication or hostbasedauthentication.However,/ETC/HOSTS.EQUIV and/ETC/SHOSTS.EQUIV will still be used. It is recommended to set the default value "Yes".# To disable tunneled clear text passwords, change to No here!#
. generate an ssh key pair on Pb1 and upload the user's public key to other servers. to connect to other servers, you must first connect to Pb1 and then jump to PB1. see
Operation Procedure: take the user root as an example. assume that Pb1: 192.168.12.83 server1: 192.168.11.78 and other users perform the same operations on www.2cto.com 1. generate a key pair in xshell in tools. The steps are not detailed. copy the public key to the Pb1 root directory. mkdir ~ in authorized_keys under ssh ~ /.
, implements the Getpasswordauthentication method, and gives the username and password in passwordauthentication:
Class Defaultauthenticator extends Authenticator {
Public Passwordauthentication getpasswordauthentication () {
return new Passwordauthentication ("USER", "PASSWORD". ToCharArray ());
}
}
Then, set it to the default (global) auth
the X11 connection is automatically redirected to a secure channel and display set.
Rhostsauthentication NoWhether the "Rhostsauthentication" setting uses rhosts security authentication.
Rhostsrsaauthentication NoWhether the "Rhostsrsaauthentication" setting uses rhosts security authentication with the RSA algorithm.
Rsaauthentication YesWhether the "Rsaauthentication" setting uses the RSA algorithm for security authentication.
Passwordauthentication
. Authorization verification aims to prevent others from sending emails randomly and reduce the generation of spam. In the previous blog, I used the Transport connect (host, port, username, password) method for verification. In fact, we can also perform verification when obtaining the Session object. There are two methods in the Session object: getDefaultInstance (prop, authenticator) and getInstance (prop, authenticator). Both methods have a common parameter authenticator, which is an Authentic
you need to use a password check yourself trigger */@Overrideprotected passwordauthentication getpasswordauthentication () { return new Passwordauthentication (UserName, Password.tochararray ());}}To inject a validation instance before running the connection:Myauthenticator auth = new Myauthenticator (Proxyuser, Proxypass); Authenticator.setdefault (auth); Instance Code ingress class /** * Network Age
send a message in Java, you must import a new package
mail.jar– the core package of outgoing mail
activation.jar– encrypts the user and password.
There are three core classes in Mail.jar:
Javax.mail.session– refers to a session with a mail server. Just one on the whole project.
Javax.mail.Message (interface)-Prepares to send data information.
MimeMessage-You can set the type of data information.
transport– it has a way to send messages.
First step: Import two jar packages
Step two: Sen
Java.net.Authenticator class is an abstract class, and we want to use the class that we need to instantiate all of a sudden. Personally, it's inconvenient here. As follows:
Publicclass Basicauthenticator extends Authenticator {
String UserName;
String password;
Public basicauthenticator (string userName, string password) {
this.username = userName;
this.password = password;
}
/**
* Called when password authorization is needed. Subclasses should
* Override
proxy and server authentication.How to use the Authenticator classAuthenticator is an abstract class which was extended by applications and once installed, was invoked to obtain usernames an D passwords for authentication interactions.Extending Java.net.AuthenticatorApplication code must override the getPasswordAuthentication() method. Note, the method is isn't abstract, and the default implementation does nothing. The following is a minimal example: Class Myauthenticator extends Authenticat
authentication with the RSA algorithm.
Rsaauthentication YesWhether the "Rsaauthentication" setting uses the RSA algorithm for security authentication.
Passwordauthentication YesWhether the "Passwordauthentication" Setting uses password authentication.
Fallbacktorsh NoThe "Fallbacktorsh" setting automatically uses RSH if an error occurs with an SSH connection.
Usersh NoWhether the "Usersh" setting uses
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.