如果一个应用程序可以调用。那应该是你JSP调用时方式有问题。比如参数未写全。或者不用USEBEAN标记。直接用JAVA语言在JSP来调用呢?

解决方案 »

  1.   

    可以说说出的是什么错吗?贴些出错信息来。我收到别人给我的代码,说是能用的,可我用在 JSP 中老是说联系不上 smtp 服务器!真是恼人!关注中!
      

  2.   

    package mails;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class QuickMailText {
     public static void sendMessage(String smtpHost,String from,String to,String subject,String messageText)throws MessagingException{
       System.out.println("Configuring mail session for:"+smtpHost);
       SmtpAuth sa=new SmtpAuth();
       sa.getuserinfo("xxxx","xxxxx");
       java.util.Properties props=new java.util.Properties();
       props.put("mail.smtp.auth","true");
       props.put("mail.smtp.host",smtpHost);
       System.out.println("Constructing message- from="+from+" to="+to);
       InternetAddress fromAddress=new InternetAddress(from);
       InternetAddress[] toAddresss=new InternetAddress[3];
       toAddresss[0]=new InternetAddress("[email protected]");
       toAddresss[1]=new InternetAddress("[email protected]");
       toAddresss[2]=new InternetAddress("[email protected]");
       int i=0;
       while(i<toAddresss.length){
       Session mailSession=Session.getDefaultInstance(props,sa);
       MimeMessage testMessage=new MimeMessage(mailSession);
       testMessage.setFrom(fromAddress);
       testMessage.addRecipient(javax.mail.Message.RecipientType.TO,toAddresss[i]);
       testMessage.setSentDate(new java.util.Date());
       testMessage.setSubject(subject);
       testMessage.setText(messageText);
       System.out.println("Message constructed");   Transport.send(testMessage);
       System.out.println("Message sent!");
       i++;
       }
     }  public static void main(String[] args){
        String smtpHost="smtp.citiz.net";
        String from="[email protected]";
        String to="xxxxxx.net";
        String subject="Test message";
        StringBuffer theMessage=new StringBuffer();
        theMessage.append("ddddhello22,\n\n");
        theMessage.append("Hope all is well on you end.\n");
        theMessage.append("Cheers");
        try{
          QuickMailText.sendMessage(smtpHost,from,to,subject,theMessage.toString());
        }catch(javax.mail.MessagingException exc){
          exc.printStackTrace();
        }
      }  static class SmtpAuth extends javax.mail.Authenticator {
       private String user,password;   public void getuserinfo(String getuser,String getpassword){
         user = getuser;
         password = getpassword;
       }
       protected javax.mail.PasswordAuthentication getPasswordAuthentication(){
         return new javax.mail.PasswordAuthentication(user,password);
       }
      }}
      

  3.   

    try
             {
                   SmtpClient client = new SmtpClient(mail.getHost());
                   client.from(mail.getFrom());
                   client.to(mail.getTo());
                   PrintStream message = client.startMessage();
                   message.println("To:" + mail.getTo());
                   message.println("Subject:" + mail.getSubject());
                   message.println();
                   message.println();
                   message.println(mail.getContext());
                   message.println();
                   client.closeServer();
                } catch (Exception e){
                     System.out.println(e.getLocalizedMessage());
                     return false;
                }
                return true;