Package com.google.code.lightssh.common.mail

Examples of com.google.code.lightssh.common.mail.MailException


   */
  protected void fillConfig( Email email,ConnectionConfig conf,
      MailAddress mailAddress,MailContent content){
     
      if( conf == null )
        throw new MailException("邮件服务器连接参数为空!");
     
      email.setHostName( conf.getHost() );
      email.setAuthentication( conf.getUsername(), conf.getPassword() );
      int port = 25;
      try{
        port = Integer.valueOf( conf.getPort()).intValue();
      }catch( NumberFormatException e ){
        log.warn("邮箱端口设置出错,使用默认值[25]。");
      }
     
      if( conf.isSsl() ){
        email.setSslSmtpPort(String.valueOf(port));
        email.setTLS(true);
      }else
        email.setSmtpPort( port );
     
      email.setSSL(conf.isSsl());
     
      //邮件地址
      if( mailAddress == null || mailAddress.getFrom()==null
          || mailAddress.getTo() == null ){
        throw new MailException("邮件发送人地址、邮件接收人地址为空!");
      }
     
      try{
        //mail from address
        Address from = mailAddress.getFrom();
        email.setFrom( from.getEmail(), from.getName() );
       
        //添加收件人
        if( mailAddress.getTo() == null || mailAddress.getTo().isEmpty() )
          throw new MailException("未设定邮件接收者!");
       
        for( Address to:mailAddress.getTo() ){
          email.addTo( to.getEmail(), to.getName() );
        }
       
        //添加抄送人
        if( mailAddress.getCc() != null ){
          for( Address cc:mailAddress.getCc() ){
            email.addCc( cc.getEmail(), cc.getName() );
          }
        }
       
        email.setSubject( content.getSubject() );
        email.setCharset( charset ); //("UTF-8")避免中文内容出现乱码
        if( email instanceof HtmlEmail)
          ((HtmlEmail) email).setHtmlMsg(content.getText());
        else
          email.setMsg( content.getText() );   
       
        email.setDebug( debug );
      }catch( org.apache.commons.mail.EmailException ee){
        throw new MailException( ee );
      }   
     
  }
View Full Code Here


      fillConfig( email,conf,mailAddress,mail );
     
      try{
        email.send();
      }catch( org.apache.commons.mail.EmailException ee){
        throw new MailException( ee );
      }   
  }
View Full Code Here

    fillConfig( email,conf,mailAddress,mail );
   
    try{
      email.send();
    }catch( org.apache.commons.mail.EmailException ee){
      throw new MailException( ee );
    }   
  }
View Full Code Here

      for( Attachment att: attachments ){     
        email.attach( att.getSource(), att.getName(), att.getDescription() );
      }
      email.send();
    }catch( org.apache.commons.mail.EmailException ee){
      throw new MailException( ee );
    }  
   
  }
View Full Code Here

TOP

Related Classes of com.google.code.lightssh.common.mail.MailException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.