James服务器连接失败异常

发布于 2024-08-06 02:32:48 字数 2123 浏览 4 评论 0原文

我正在尝试将 Javamail 应用程序连接到 James 服务器,但收到

javax.mail.MessagingException: Could not connect to SMTP host:localhost, port:4555; 嵌套异常是: java.net.SocketException: Invalid argumentt: connect

这是代码,这给我带来了一个小问题:

import java.security.Security;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class mail  {

public static void main(String[] argts)
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());


       String mailHost = "your.smtp.server";



        String to = "blue@localhost";



        String from = "red@localhost";
        String subject = "jdk";
        String body = "Down to wind";

        if ((from != null) && (to != null) && (subject != null)  && (body != null)) // we have mail to send
        {

        try {


            //Get system properties
            Properties props = System.getProperties();


            props.put("mail.smtp.user", "red");
            props.put("mail.smtp.host", "localhost");
            props.put("mail.debug", "true");
            props.put("mail.smtp.port", 4555);


            props.put("mail.smtp.socketFactory.port", 4555);
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.socketFactory.fallback", "false");

            Session session = Session.getInstance(props,null);


            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO, new InternetAddress[] { new InternetAddress(to) });
            message.setSubject(subject);
            message.setContent(body, "text/plain");
            message.setText(body);
            Transport.send(message);


            System.out.println("<b>Thank you.  Your message to " + to + " was successfully sent.</b>");

        } catch (Throwable t) {
           System.out.println("Teri maa ki "+t);
        }


        }

    }




}

提前致谢。 :)

I'm trying to connect Javamail application to James server, but I'm getting

javax.mail.MessagingException: Could not connect to SMTP host:localhost, port:4555;
nested exception is: java.net.SocketException: Invalid arguent: connect

Here's the code, which is creating a little problem for me:

import java.security.Security;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class mail  {

public static void main(String[] argts)
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());


       String mailHost = "your.smtp.server";



        String to = "blue@localhost";



        String from = "red@localhost";
        String subject = "jdk";
        String body = "Down to wind";

        if ((from != null) && (to != null) && (subject != null)  && (body != null)) // we have mail to send
        {

        try {


            //Get system properties
            Properties props = System.getProperties();


            props.put("mail.smtp.user", "red");
            props.put("mail.smtp.host", "localhost");
            props.put("mail.debug", "true");
            props.put("mail.smtp.port", 4555);


            props.put("mail.smtp.socketFactory.port", 4555);
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.socketFactory.fallback", "false");

            Session session = Session.getInstance(props,null);


            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO, new InternetAddress[] { new InternetAddress(to) });
            message.setSubject(subject);
            message.setContent(body, "text/plain");
            message.setText(body);
            Transport.send(message);


            System.out.println("<b>Thank you.  Your message to " + to + " was successfully sent.</b>");

        } catch (Throwable t) {
           System.out.println("Teri maa ki "+t);
        }


        }

    }




}

Thanks in advance. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天荒地未老 2024-08-13 02:32:48
        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.port", 4555);

这两行使您的代码连接到您的本地主机(您自己的机器?),端口 4555。我认为有问题的 SMTP 服务器正在其他主机上运行。将主机名放入第一个属性中,将正确的端口(通常是 25)放入第二个属性中,这样就可以工作了。

如果这没有帮助,请提供有关您的设置的详细信息:运行 SMTP 服务器的主机、它正在侦听的端口、它是否使用 SSL(根据您的代码,它使用 SSL,是吗?)、您在哪里运行客户端、. ..

        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.port", 4555);

Those two lines make your code connect to your localhost (your own machine?), port 4555. I presume the SMTP server in question is running on some other host. Put the host name into the first property, and the correct port (usually 25) into the second, and it would work.

If that doesn't help, please provide details on your setup: host where you run SMTP server, port it's listening on, does it use SSL (according to your code it does, eh?), where are you running the client, ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文