我遇到类试的问题
把邮件服务器的地址改为IP地址就能连接上了
比如说smtp.XXX.com是服务器的话
改成IP地址不要加SMTP

解决方案 »

  1.   

    是你的方法不对,我开发的javamail就可以。
      

  2.   

    SMTP改IP的方法我试过了不行楼上的大虾可以把发邮件的部分代码贴出来吗?
      

  3.   

    呵呵~~~~~~~~用javamail可以开发企业内部OA系统的通知子模块,有谁做过吗?
      

  4.   

    我这儿有代码,供你参考(发信需要身份验证):
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    public class sendMail
    {
          public static void main(String args[]) throws Exception
          {            String host = "smtp.sina.com.cn";
                String from =   "[email protected]";
                String to = "[email protected]";
                String username = "javamail";
                String password = "password";            // Get system properties
                // Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中
                Properties props = new Properties();            // Setup mail server
                props.put("mail.smtp.host", host);
                props.put("mail.smtp.auth", "true"); //这样才能通过验证            // Get session
                Session session = Session.getDefaultInstance(props);            // watch the mail commands go by to the mail server
                session.setDebug(true);            // Define message
                MimeMessage message = new MimeMessage(session);
                message.setFrom(new InternetAddress(from));
                message.addRecipient(Message.RecipientType.TO,
                   new InternetAddress(to));
                message.setSubject("Hello JavaMail");
                message.setText("Welcome to JavaMail");            // Send message
                message.saveChanges();
                Transport transport = session.getTransport("smtp");
                transport.connect(host, username, password);
                transport.sendMessage(message, message.getAllRecipients());
                transport.close();
          }
    }  
      

  5.   

    我把我的代码贴出来,大伙看看有没有毛病?<%@ page
      import="java.util.*, javax.mail.*, javax.mail.internet.*"
      errorPage="errorpage.jsp" %>
    <%
      Properties props = new Properties();
      
      props.put("mail.smtp.host", "smtp.21cn.com");
      props.put("mail.smtp.auth", "true");//permit SMTP
      
      Session s = Session.getDefaultInstance(props);
      
      Transport transport = s.getTransport("smtp");
      transport.connect( "smtp.21cn.com", "username", "******" );//
         
      MimeMessage message = new MimeMessage(s); 
      
      InternetAddress from = new InternetAddress("[email protected]");
      message.setFrom(from);  
        try {
        String toValue = request.getParameter("to");
        if(!toValue.equals("")) {
          InternetAddress to = new InternetAddress(toValue);
          message.addRecipient(Message.RecipientType.TO, to);
        } else {
          throw new MessagingException
                  ("You must fill in a value for the \"to\" field.");
        }    String subject = request.getParameter("subject");
        if(!subject.equals("")) {
          message.setSubject(subject);
        } else {
          throw new MessagingException
                  ("You must fill in a value for the \"subject\" field.");
        }    String text = request.getParameter("text");
        if(!text.equals("")) {
          MimeMultipart mm = new MimeMultipart();
          MimeBodyPart mbp = new MimeBodyPart();
          String type = request.getParameter("type");
          mbp.setContent(text, type);
          mm.addBodyPart(mbp);
          message.setContent(mm);
        } else {
          throw new MessagingException
                  ("You must fill in a value for the body of the message.");
        }
      } catch(MessagingException e) {
        throw new MessagingException("Error getting form values: " +
                                     e.toString());
      }
      try {
           
           
           transport.send(message);

      } catch(MessagingException e) {
        throw new MessagingException("Cannot send mail. Please contact " +
                "the <a href=\"mailto:[email protected]\">administrator</a>.");
      } finally {transport.close();// 
        
      }