0

这个错误让我发疯。当我的应用程序抛出异常时,我正在尝试向自己发送电子邮件,但我刚刚开始收到此错误。我能够成功 ping 主机,并且在使用 nslookup 时可以获得本地 IP 地址。有任何想法吗?谢谢

        try
    {
        java.util.Date d = new Date();
        Properties props = new Properties();

        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.host", "My server address");
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.smtp.port", "25");

        Authenticator authenticator = new SmtpAuthenticator();

        Session mailSession = Session.getDefaultInstance(props, authenticator);
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setFrom(new InternetAddress("My email"));
        message.setSubject("Voicemail Notification");
        message.setContent("You are receiving this automatic message because there has been a voicemail left in the system on " +d.toString() + " for the division of the company you work for. \n" +
        "Please respond promptly.  Thanks!\n" +
        "Private Ip address?file=" + messageName + ".gsm", "text/plain");
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
        transport.connect();
        transport.sendMessage(message,
                message.getRecipients(Message.RecipientType.TO));
        transport.close();

        System.out.println("Email Sent!");

    }
    catch(Exception ex)
    {
        ex.printStackTrace();
        System.out.println("Unable to send email notification to: " + emailTo);
    }
4

1 回答 1

0

尝试使用命令行尝试telnet mailserveraddress 25这将告诉您邮件服务器是否实际上正在运行并侦听端口 25。如果您在 telnet 中收到相同的错误,则表示您的邮件服务器运行不正常。

于 2012-11-08T20:29:29.080 回答