使用Javamail API的SMTP连接失败? [英] smtp connection is failing using javamail api?

查看:292
本文介绍了使用Javamail API的SMTP连接失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试连接到smtp主机时,它显示连接失败并在本地交换服务器上的端口25上响应-1,但是我能够连接到gmail smtp主机以从gmail发送电子邮件,我正在使用以下代码.

whenever i am trying to connect to smtp host it shows connection failed with response -1 on port 25 on my local exchange server, but i am able to connect to gmail smtp host to send emails from gmail i am using below code.

        Properties props = System.getProperties();
        props.put("mail.smtp.host", "localexchange.server.address");
        props.put("mail.from", "emailid");
        Session session = Session.getInstance(props, null);

        try {
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom();
            msg.setRecipients(Message.RecipientType.TO,
                              "emailid");
            msg.setSubject("JavaMail hello world example");
            msg.setSentDate(new Date());
            msg.setText("Hello, world!\n");
            Transport.send(msg);
        } catch (MessagingException mex) {
            System.out.println("send failed, exception: " + mex);
        }

推荐答案

JavaMail FAQ 具有有关调试连接问题的提示.你尝试过吗?

这篇关于使用Javamail API的SMTP连接失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆