In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the abnormal problems of sending email in Java Mail". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the abnormal problems in sending email in Java Mail?"
one。 Common Session properties
When sending email using JavaMail, you generally need to specify some attribute parameters, which are constructed by using java.util.Properties through Session. The attributes commonly used to construct Session are as follows:
Mail.smtp.user
The default user name for SMTP.
Mail.smtp.host
The SMTP server to connect to.
Mail.smtp.port
The port number of the SMTP server to connect to. If connect does not specify the port number, use it. The default value is 25.
Mail.smtp.auth
The default is false, if it is true, try to authenticate the user using the AUTH command.
Mail.transport.protocol
The protocol (smtp, pop3, imap, nntp) to load the session.
Mail.smtp.connectiontimeout
Socket connection timeout value (in milliseconds). The default value is not timeout.
Mail.smtp.timeout
Socket I peg O timeout value (in milliseconds). The default value is not timeout.
Mail.smtp.from
The Email address used by SMTP MAIL to set the return address of the message. The default is Message.getFrom () or InternetAddress.getLocalAddress (). Note: mail.smtp.user is preferred.
Mail.smtp.localhost
Localhost name, which defaults to InetAddress.getLocalHost () .getHostName (). If JDK and name service are configured correctly, they generally do not need to be set up.
Mail.host
The host of the mail interaction.
Mail.smtp.ehlo
If false, then login using the EHLO command will not be attempted, and the default is true. Usually the EHLO command fails and falls back to the HELO command. This property is available only if the server does not have the fail EHLO property or does not implement the EHLO property.
Mail.user
The user name to log in to the mail server (required to send mail).
Mail.from
Sender address (required when sending mail).
two。 Summary of abnormal problems
1. Sending mail exception
When sending mail using springmail, the mail.smtp.localhost was not specified, and the code was running normally, but suddenly one day, the hostname of the new device changed and the email could not be sent normally. The exception is as follows:
Finally, the investigation found that it was the problem with hostname.
Solution 1:
Modify the / etc/hosts file to add the mapping between hostname and ip addresses as follows, and the last behavior is added:
Solution 2:
Add the configuration of mail.smtp.localhost to the Session attribute of the outgoing message, as follows (generally, localhost exists)
Prop.put ("mail.smtp.localhost", "localhost")
Reason:
When JavaMail sends mail, it will extract the local hostname and send it in the form of ip. However, under the linux server, the native ip address corresponding to hostname cannot be resolved, so JavaMail cannot call ip to send. When Postfix receives such a message, it will refuse to send it, resulting in a 501 error. (the windows server can send it because it uses the non-netbios protocol to obtain the ip address of the host, so it can get the ip.)
When there is a problem with the configuration of / etc/hosts, the following exception has also occurred for reference:
Thank you for your reading, the above is the content of "what is the abnormal problem of sending email in Java Mail". After the study of this article, I believe you have a deeper understanding of the abnormal problem of sending email in Java Mail, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.