package beanMailer;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
public class SMTPBean implements Serializable{
private Socket smtp;
private BufferedReader input;
private PrintStream output;
private String smtpServer = "your.smtp.server";
private String serverReply;
private int port = 25;
public SMTPBean() {
}
public void sendMail(String mailfrom, String mailto, String subject, String message) throws SMTPException{
connect();
hail(mailfrom, mailto);
sendMessage(mailfrom, mailto, subject, message);
logout();
}
public void connect() throws SMTPException {
try {
smtp = new Socket(smtpServer, port);
input = new BufferedReader(new InputStreamReader(smtp.getInputStream()));
output = new PrintStream(smtp.getOutputStream());
serverReply = input.readLine();
if (serverReply.charAt(0) == '2' || serverReply.charAt(0) == '3') {
}
else {
throw new SMTPException("Error connecting to SMTP server " + smtpServer + " on port " + port);
}
}
catch(Exception e) {
throw new SMTPException(e.getMessage());
}
}
public void hail(String mailfrom, String mailto) throws SMTPException {
if (submitCommand("HELO " + smtpServer))
throw new SMTPException("Error occured during HELO command.");
if (submitCommand("MAIL FROM: " + mailfrom))
throw new SMTPException("Error during MAIL command.");
if (submitCommand("RCPT TO: " + mailto))
throw new SMTPException("Error during RCPT command.");
}
public void sendMessage(String mailfrom, String mailto, String subject, String message) throws SMTPException {
Date ldate_today = new Date(System.currentTimeMillis());
SimpleDateFormat lgmt_date = new SimpleDateFormat("d MMM yyyy HH:mm:ss 'GMT'");
lgmt_date.setTimeZone(TimeZone.getTimeZone("GMT"));
lgmt_date.format(ldate_today);
if (submitCommand("DATA"))
throw new SMTPException("Error during DATA command.");
String header = "From: " + mailfrom + "\r\n";
header += "To: " + mailto + "\r\n";
header += "Subject: " + subject + "\r\n";
header += "Date: " + lgmt_date + "\r\n\r\n";
if (submitCommand(header + message + "\r\n."))
throw new SMTPException("Error during mail transmission.");
}
private boolean submitCommand(String command) throws SMTPException {
try {
output.print(command + "\r\n");
serverReply = input.readLine();
if (serverReply.charAt(0) == '4' || serverReply.charAt(0) == '5')
return true;
else
return false;
}
catch(Exception e) {
throw new SMTPException(e.getMessage());
}
}
public String getServerReply() {
return serverReply;
}
public int getPort(){
return port;
}
public void setPort(int newPort){
port = newPort;
}
public String getSmtpServer(){
return smtpServer;
}
public void setSmtpServer(String newSmtpServer){
smtpServer = newSmtpServer;
}
public void logout() throws SMTPException {
try {
if (submitCommand("Quit"))
throw new SMTPException("Error during QUIT command");
input.close();
output.flush();
output.close();
smtp.close();
}
catch(Exception e) {
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JSP项目申报管理系统.rar
共154个文件
jsp:77个
gif:59个
html:6个
需积分: 20 15 下载量 12 浏览量
2019-07-10
17:41:31
上传
评论 1
收藏 481KB RAR 举报
温馨提示
JSP项目申报管理系统,MSSQL数据库,系统实现的功能:功能:申报指南、专家登录、修改帐户、项目评审、专家信息、单位信息、分配浏览、系统功能辅助说明等。。界面运行效果请参见截图。
资源推荐
资源详情
资源评论
收起资源包目录
JSP项目申报管理系统.rar (154个子文件)
firm.class 2KB
opendb.class 2KB
exam.class 2KB
ban8.gif 28KB
ff.gif 18KB
ping.gif 11KB
logo2.gif 3KB
chengg.gif 2KB
chengg.gif 2KB
chengg.gif 2KB
chengg.gif 2KB
tub.gif 2KB
zongping1.gif 2KB
pingshen1.gif 2KB
shenbao1.gif 2KB
z_fen.gif 2KB
z_sort.gif 2KB
z_changeMind.gif 2KB
tuijian.gif 2KB
s_item2.gif 1KB
changePw.gif 1KB
welcome.gif 1KB
addExpert.gif 1KB
save.gif 1KB
addUnit.gif 1KB
leadingMind.gif 1KB
expertMind.gif 1KB
z_distribute.gif 1KB
z_setup.gif 1KB
p_mind.gif 1KB
p_info.gif 1KB
print1.gif 1KB
s_info.gif 1KB
s_declare.gif 1KB
z_item.gif 1KB
shutdown.gif 1KB
p_item.gif 1KB
p_exam.gif 1KB
change.gif 1004B
refer.gif 977B
login.gif 970B
close.gif 940B
print.gif 890B
p_expertinfo.gif 667B
s_unitinfo.gif 658B
z_itemSetup.gif 654B
z_zongping.gif 649B
s_item.gif 630B
s_item1.gif 627B
z_list1.gif 626B
p_item1.gif 621B
p_item2.gif 617B
z_list2.gif 598B
back.gif 540B
beijin.gif 495B
lianxi.gif 343B
jieshao.gif 266B
pingshen.gif 266B
zhinan.gif 265B
shenbao.gif 264B
zongping.gif 263B
ban00.gif 219B
mu.html 6KB
jieg.html 326B
jieg.html 326B
jieg.html 326B
index.html 297B
bti.html 177B
SMTPBean.java 3KB
opendb.java 2KB
exam.java 2KB
firm.java 2KB
SMTPException.java 143B
Copy of s_changeItem.jsp 44KB
s_changeItem.jsp 42KB
s_itemInfo.jsp 39KB
z_itemSetup.jsp 23KB
p_changeInfo.jsp 21KB
s_showItem.jsp 18KB
z_showItem.jsp 18KB
z_scoreCheck.jsp 16KB
p_mind.jsp 16KB
z_sortItem.jsp 15KB
p_showItem.jsp 15KB
z_item.jsp 14KB
s_changeInfo.jsp 13KB
p_showMind.jsp 12KB
z_showMind.jsp 12KB
s_expertInfo.jsp 11KB
p_showInfo.jsp 10KB
z_showExpert.jsp 9KB
s_showInfo.jsp 9KB
z_expert.jsp 9KB
z_showUnit.jsp 9KB
z_unit.jsp 8KB
s_item.jsp 8KB
s_itemDeclare.jsp 8KB
s_checkItem.jsp 8KB
s_expert.jsp 8KB
p_item.jsp 7KB
共 154 条
- 1
- 2
资源评论
weixin_39841848
- 粉丝: 509
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功