当前位置: 技术问答>java相关
最近发现大家对JavaMail的讨论较多,我也来一贴——SMTPClient Bean。希望对大家有点用。
来源: 互联网 发布时间:2015-05-17
本文导语: /* *Source File Name: SMTPClient.java *@author : takecare@etang.com */ //the content is too large, the following is part one: import java.io.File; import java.io.IOException; import java.util.*; import javax.mail.*; import javax.mail.internet.*; import j...
/*
*Source File Name: SMTPClient.java
*@author : takecare@etang.com
*/
//the content is too large, the following is part one:
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;
import javax.activation.*;
public class SMTPClient implements ConnectionListener, TransportListener {
private InternetAddress hostname;
private String host;
private String from;
private InternetAddress fromAddress;
private InternetAddress receiveAddress[];
private InternetAddress replyTos[];
private String receive[];
private String auth;
private String ehlo;
private String username;
private String password;
private String subject;
private String content;
private String contentType;
private String charset;
private MimeBodyPart mimeParts[];
private String attachmentFiles[];
private String reply[];
private Date sendDate;
private boolean debugFlag;
public SMTPClient() {
from = "";
receive = new String[0];
host = "localhost";
subject = "kingtone";
content = "";
contentType = "text/plain";
charset = "gb2312";
mimeParts = new MimeBodyPart[0];
attachmentFiles = new String[0];
reply = new String[0];
sendDate = new Date();
debugFlag = false;
auth = "false";
ehlo = "false";
}
public void setFromAddress(String fromAddr) {
from = fromAddr;
}
public void setFromAddress(InternetAddress fromAddr) {
fromAddress = fromAddr;
from = null;
}
public String getFromAddress() {
return from;
}
public void setToAddresses(String toAddress[]) {
receive = toAddress;
}
public void setToAddress(String toAddress) {
receive = (new String[] {toAddress} );
}
public void setToAddresses(InternetAddress to[]) {
receiveAddress = to;
receive = null;
}
public String[] getToAddresses() {
return receive;
}
public void setHost(String h) {
host = h;
}
public void setHost(InternetAddress h) {
hostname = h;
}
public String getHost() {
return host;
}
public void setSubject(String subj) {
subject = subj;
}
public String getSubject() {
return subject;
}
public void setReplyToAddresses(String replyTo[]) {
reply = replyTo;
}
public void setReplyToAddresses(InternetAddress replyTo[]) {
replyTos = replyTo;
reply = null;
}
public void setReplyToAddress(String replyTo) {
reply = (new String[] {replyTo});
}
public String[] getReplyToAddresses() {
return reply;
}
public void setTextContent(String cont) {
content = cont;
}
public String getTextContent() {
return content;
}
public void setContentType(String contType) {
contentType = contType;
}
public String getContentType() {
return contentType;
}
public void setCharset(String encoding) {
charset = encoding;
}
public String getCharset() {
return charset;
}
public void enableAUTH() {
auth = "true";
ehlo = "true";
}
public void disableAUTH() {
auth = "false";
ehlo = "false";
}
public void setMimeParts(MimeBodyPart mimeParts[]) {
mimeParts = mimeParts;
attachmentFiles = null;
}
public MimeBodyPart[] getMimeParts() {
return mimeParts;
}
public void setFileAttachments(String files[]) {
attachmentFiles = files;
}
public void setFileAttachment(String filename) {
attachmentFiles = (new String[] {
filename
});
mimeParts = null;
}
public String[] getFileAttachments() {
return attachmentFiles;
}
public void setDebug(boolean debug) {
debugFlag = debug;
}
public boolean getDebug() {
return debugFlag;
}
public void setSentDate(Date sentDate) {
sendDate = sentDate;
}
public Date getSentDate() {
return sendDate;
}
public void setUserName(String name) {
username = name;
}
public String getUserName() {
return username;
}
public void setPassword(String passwd) {
password = passwd;
}
public String getPassword() {
return password;
}
*Source File Name: SMTPClient.java
*@author : takecare@etang.com
*/
//the content is too large, the following is part one:
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;
import javax.activation.*;
public class SMTPClient implements ConnectionListener, TransportListener {
private InternetAddress hostname;
private String host;
private String from;
private InternetAddress fromAddress;
private InternetAddress receiveAddress[];
private InternetAddress replyTos[];
private String receive[];
private String auth;
private String ehlo;
private String username;
private String password;
private String subject;
private String content;
private String contentType;
private String charset;
private MimeBodyPart mimeParts[];
private String attachmentFiles[];
private String reply[];
private Date sendDate;
private boolean debugFlag;
public SMTPClient() {
from = "";
receive = new String[0];
host = "localhost";
subject = "kingtone";
content = "";
contentType = "text/plain";
charset = "gb2312";
mimeParts = new MimeBodyPart[0];
attachmentFiles = new String[0];
reply = new String[0];
sendDate = new Date();
debugFlag = false;
auth = "false";
ehlo = "false";
}
public void setFromAddress(String fromAddr) {
from = fromAddr;
}
public void setFromAddress(InternetAddress fromAddr) {
fromAddress = fromAddr;
from = null;
}
public String getFromAddress() {
return from;
}
public void setToAddresses(String toAddress[]) {
receive = toAddress;
}
public void setToAddress(String toAddress) {
receive = (new String[] {toAddress} );
}
public void setToAddresses(InternetAddress to[]) {
receiveAddress = to;
receive = null;
}
public String[] getToAddresses() {
return receive;
}
public void setHost(String h) {
host = h;
}
public void setHost(InternetAddress h) {
hostname = h;
}
public String getHost() {
return host;
}
public void setSubject(String subj) {
subject = subj;
}
public String getSubject() {
return subject;
}
public void setReplyToAddresses(String replyTo[]) {
reply = replyTo;
}
public void setReplyToAddresses(InternetAddress replyTo[]) {
replyTos = replyTo;
reply = null;
}
public void setReplyToAddress(String replyTo) {
reply = (new String[] {replyTo});
}
public String[] getReplyToAddresses() {
return reply;
}
public void setTextContent(String cont) {
content = cont;
}
public String getTextContent() {
return content;
}
public void setContentType(String contType) {
contentType = contType;
}
public String getContentType() {
return contentType;
}
public void setCharset(String encoding) {
charset = encoding;
}
public String getCharset() {
return charset;
}
public void enableAUTH() {
auth = "true";
ehlo = "true";
}
public void disableAUTH() {
auth = "false";
ehlo = "false";
}
public void setMimeParts(MimeBodyPart mimeParts[]) {
mimeParts = mimeParts;
attachmentFiles = null;
}
public MimeBodyPart[] getMimeParts() {
return mimeParts;
}
public void setFileAttachments(String files[]) {
attachmentFiles = files;
}
public void setFileAttachment(String filename) {
attachmentFiles = (new String[] {
filename
});
mimeParts = null;
}
public String[] getFileAttachments() {
return attachmentFiles;
}
public void setDebug(boolean debug) {
debugFlag = debug;
}
public boolean getDebug() {
return debugFlag;
}
public void setSentDate(Date sentDate) {
sendDate = sentDate;
}
public Date getSentDate() {
return sendDate;
}
public void setUserName(String name) {
username = name;
}
public String getUserName() {
return username;
}
public void setPassword(String passwd) {
password = passwd;
}
public String getPassword() {
return password;
}
|
回头看看
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。