java.net.UnknownHostException:smtps.aruba.it

java.net.UnknownHostException:smtps.aruba.it,smtp,jakarta-mail,centos7,unknown-host,aruba,Smtp,Jakarta Mail,Centos7,Unknown Host,Aruba,我正在使用javax.mail和邮件aruba帐户 在windows和centos7机器上,一切正常。 但在另一台特定的centos7机器(服务器下)上,tomcat7的控制台显示: 我看到了谷歌和stackoverflow向我推荐的每一篇帖子,但没有任何效果 我认为这是一个机器环境问题 邮件类 import java.io.IOException; import java.util.Properties; import javax.mail.Message; import javax.ma

我正在使用javax.mail和邮件aruba帐户

在windows和centos7机器上,一切正常。 但在另一台特定的centos7机器(服务器下)上,tomcat7的控制台显示:

我看到了谷歌和stackoverflow向我推荐的每一篇帖子,但没有任何效果

我认为这是一个机器环境问题

邮件类

import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.mail.MailSender;
import org.springframework.stereotype.Service;
     @Service("mailSender")
    public class ApplicationMailer {

        private static javax.mail.Session session=null; 
        private static Resource resource = new ClassPathResou

rce("resources/mail.properties");

    static {
        try {
            final Properties props = PropertiesLoaderUtils.loadProperties(resource);
            if (props!=null)
            {
                session = javax.mail.Session
                    .getInstance(props, new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(props.getProperty("email.username"),
                                    props.getProperty("email.password"));
                        }

                    });
            }
        } catch (IOException e) {
            session=null;
            e.printStackTrace();
        }
    }


    @Autowired
    private MailSender mailSender;


    public MailSender getMailSender() {
        return mailSender;
    }

    public void setMailSender(MailSender mailSender) {
        this.mailSender = mailSender;
    }

    /**
     * This method will send compose and send the message 
     * @throws IOException 
     * @throws MessagingException 
     * @throws AddressException 
     * */
    public void sendMail(String to, String subject, String body) throws IOException, AddressException, MessagingException{
            Message mail = new MimeMessage(session);
            final Properties props = PropertiesLoaderUtils.loadProperties(resource);
            mail.setFrom(new InternetAddress(props.getProperty("mail.from")));
            mail.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            mail.setSubject(subject);
            mail.setContent(body, "text/html");
            Transport.send(mail); 

    }
}
mail.debug=true
mail.from=*****
email.username=******
email.password=******

mail.smtp.host=smtps.aruba.it
mail.smtp.port=465
mail.smtp.localhost=localhost
mail.mime.charset=UTF-8
mail.smtp.auth=true

mail.smtp.ssl.enable=true
mail.transport.protocol=smtps
mail.properties

import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.mail.MailSender;
import org.springframework.stereotype.Service;
     @Service("mailSender")
    public class ApplicationMailer {

        private static javax.mail.Session session=null; 
        private static Resource resource = new ClassPathResou

rce("resources/mail.properties");

    static {
        try {
            final Properties props = PropertiesLoaderUtils.loadProperties(resource);
            if (props!=null)
            {
                session = javax.mail.Session
                    .getInstance(props, new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(props.getProperty("email.username"),
                                    props.getProperty("email.password"));
                        }

                    });
            }
        } catch (IOException e) {
            session=null;
            e.printStackTrace();
        }
    }


    @Autowired
    private MailSender mailSender;


    public MailSender getMailSender() {
        return mailSender;
    }

    public void setMailSender(MailSender mailSender) {
        this.mailSender = mailSender;
    }

    /**
     * This method will send compose and send the message 
     * @throws IOException 
     * @throws MessagingException 
     * @throws AddressException 
     * */
    public void sendMail(String to, String subject, String body) throws IOException, AddressException, MessagingException{
            Message mail = new MimeMessage(session);
            final Properties props = PropertiesLoaderUtils.loadProperties(resource);
            mail.setFrom(new InternetAddress(props.getProperty("mail.from")));
            mail.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            mail.setSubject(subject);
            mail.setContent(body, "text/html");
            Transport.send(mail); 

    }
}
mail.debug=true
mail.from=*****
email.username=******
email.password=******

mail.smtp.host=smtps.aruba.it
mail.smtp.port=465
mail.smtp.localhost=localhost
mail.mime.charset=UTF-8
mail.smtp.auth=true

mail.smtp.ssl.enable=true
mail.transport.protocol=smtps
dispacer servlet

  <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtps.aruba.it" />
        <property name="port" value="465" />
        <property name="protocol" value="smtps" />
        <property name="username" value="*****" />
        <property name="password" value="*****" />
        <property name="javaMailProperties">
            <props>
                <prop key="mail.transport.protocol">smtps</prop>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.debug">true</prop>
                <prop key="mail.smtp.localhost">localhost</prop>
                <prop key="mail.mime.charset">UTF-8</prop>
<!--                <prop key="mail.smtps.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> -->
                <prop key="mail.smtps.ssl.enable">false</prop>
            </props>
        </property>
    </bean>

smtps
真的
真的
真的
本地服务器
UTF-8
假的

错误信息非常清楚。如果无法将服务器名称解析为IP地址,则会引发
UnknownHostException
。这很可能不是Java或JavaMail问题,而是与底层操作系统的配置有关的问题

为了确保您可以打开shell会话并键入以下命令之一

主机smtps.aruba.it

挖smtps.aruba.it

nstps.aruba.it

(根据安装的内容,可能不存在一个或多个命令)


如果答案是主机未知,则可以停止对java应用程序进行故障排除;-)

错误信息非常清楚。如果无法将服务器名称解析为IP地址,则会引发
UnknownHostException
。这很可能不是Java或JavaMail问题,而是与底层操作系统的配置有关的问题

为了确保您可以打开shell会话并键入以下命令之一

主机smtps.aruba.it

挖smtps.aruba.it

nstps.aruba.it

(根据安装的内容,可能不存在一个或多个命令)


如果答案是主机未知,则可以停止对java应用程序进行故障排除;-)

在服务器上尝试。可能服务器上的名称服务配置不正确。请在服务器上尝试。可能服务器上的名称服务配置不正确。太好了,你说得对!这是一个机器环境问题。我在终端上写:
ping smtps.aruba.it
,上面写着未知主机。那么我该如何解决这个问题呢?DNS配置是操作系统的一部分,所以这里没有答案,但如果您将DNS配置[您的操作系统]输入您选择的搜索引擎,应该会有大量搜索结果。既然我回答了你的问题,你可以考虑接受它;太好了,你说得对!这是一个机器环境问题。我在终端上写:
ping smtps.aruba.it
,上面写着未知主机。那么我该如何解决这个问题呢?DNS配置是操作系统的一部分,所以这里没有答案,但如果您将DNS配置[您的操作系统]输入您选择的搜索引擎,应该会有大量搜索结果。既然我回答了你的问题,你可以考虑接受它;