?? mailsender.sql
字號:
create or replace and compile java source named mailsender as
import java.io.File;
import java.io.PrintWriter;
import java.sql.*;
import java.util.*;
/**
* @author junsansi
* @qq 5454589
* @website www.5ienet.com
*/
public class MailSender {
//ishtml 1是 0否
public static MailService ms = null;
/**
* initialize mailService
* @throws Exception
*/
void init() throws Exception {
ms = new MailService("smtp.sina.com.cn"); //smtp地址
try {
ms.setFrom("junsansi@sina.com"); //發送郵箱(不重要,只是顯示)
ms.setUserName("junsansi@sina.com"); //郵箱帳號
ms.setPassword("123456"); //輸入你的郵箱密碼,呵呵,此處是我瞎寫,您就表嘗試用這個登陸了
ms.setSmtpAuth(true);
} catch (Exception e) {
throw e;
}
}
/**
* sendmail no attachment
* @param to String
* @param sendTopic String
* @param sendContent String
* @param ishtml int
* @return String
*/
public static String send(String to, String sendTopic,
String sendContent, int ishtml) {
return send(to, null, null, sendTopic, sendContent, null, ishtml);
}
/**
* sendmail by attachment
* @param to String
* @param sendTopic String
* @param sendContent String
* @param filename String
* @param ishtml int
* @return String
*/
public static String send(String to, String sendTopic,
String sendContent, String filename, int ishtml) {
return send(to, null, null, sendTopic, sendContent, filename, ishtml);
}
/**
* sendmail by cc,bcc but no attachment
* @param to String
* @param cc String
* @param bcc String
* @param sendTopic String
* @param sendContent String
* @param ishtml int
* @return String
*/
public static String send(String to, String cc, String bcc,
String sendTopic,
String sendContent, int ishtml) {
return send(to, cc, bcc, sendTopic, sendContent, null, ishtml);
}
/**
* sendmail by cc,bcc and attachment
* @param to String
* @param cc String
* @param bcc String
* @param sendTopic String
* @param sendContent String
* @param filename String
* @param ishtml int
* @return String
*/
public static String send(String to, String cc, String bcc,
String sendTopic,
String sendContent, String filename, int ishtml) {
MailSender makeSta = new MailSender();
String result = null;
try {
if (ms == null) { //調試smtp服務器的時候,將本段if去掉,只保留makeSta.init();不然修改過后也不會被編譯
makeSta.init();
}
ms.setTo(to);
if (cc != null ) {
cc = cc.trim();
if (cc.length() > 0){
String[] cclist = split(cc, ",");
Vector list = new Vector(cclist.length);
int i;
for (i = 0; i < cclist.length; i++) {
list.add(cclist[i]);
}
ms.setCc(list);
}
}
if (bcc != null) {
bcc = bcc.trim();
if (bcc.length() > 0){
String[] bcclist = split(bcc, ",");
Vector list = new Vector(bcclist.length);
int i;
for (i = 0; i < bcclist.length; i++) {
list.add(bcclist[i]);
}
ms.setBcc(list);
}
}
if (filename != null) {
filename = filename.trim();
if (filename.length() > 0){
ms.setFilename(filename);
}
}
ms.setSubject(sendTopic);
if (ms.send(sendContent, ishtml)) {
result = "successed to sent the mail to " + to;
} else {
result = "Failed to sent the mail.";
}
} catch (Exception e) {
e.printStackTrace();
result = "Failed to sent the mail, err:" + e.getMessage();
} finally {
return result;
}
}
/**
* no split function in java.lang.String in jdk1.3
* so,i have write on by my self.
* @param strtxt String
* @param key String
* @return String[]
*/
public static String[] split(String strtxt, String key) {
StringTokenizer st = new StringTokenizer(strtxt, key);
ArrayList al = new ArrayList();
while (st.hasMoreTokens()) {
al.add(st.nextToken());
}
String[] result = new String[al.size()];
al.toArray(result);
return result;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -