利用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.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();
}
}
}
更多精彩
赞助商链接