WEB开发网
开发学院WEB开发Jsp 利用Jmail发带附件的邮件 阅读

利用Jmail发带附件的邮件

 2008-01-05 18:33:28 来源:WEB开发网   
核心提示:package com.sidiw.util.jmail;import java.util.Date;import java.util.HashMap;import java.util.Map;import javax.activation.DataHandler;import javax.activation.Dat

package com.sidiw.util.jmail;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeMessage.RecipientType;

import sun.misc.BASE64Encoder;

public class SendMail {
   /** 文本编码 */
   PRivate String encode;

   /** 文本还是Html内容 */
   private boolean HTML;

   private Session session;

   private Transport transport;

   private BASE64Encoder enc = new sun.misc.BASE64Encoder();

   public SendMail() {
     this.encode = "GBK";
     this.HTML = true;
   }

   public SendMail(String encode, boolean html) {
     this.encode = encode;
     this.HTML = html;
   }

   public boolean connect(String smtpHost, String uid, String pwd) {
     boolean result = false;

   ConnectMail connect = new ConnectMail();
     result = connect.connectSmtp(smtpHost, uid, pwd);
     this.session = connect.getSession();
     this.transport = connect.getTransport();

   return result;
   }

   public void close() {
     if (this.transport != null) {
       try {
         this.transport.close();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }


Tags:利用 Jmail 发带

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接