/*
*author:tyfun
*datetime:2003.01.09
*package:com.westarsoft.function
*/
package com.westarsoft.function;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class sendmail {
private string smtpserver = new string();
private string from = new string();
private string subject = new string();
private string content = new string();
private string user = new string();
private string password = new string();
private string fileattachment = new string();
public string getsmtpserver() {
return smtpserver;
}
public void setsmtpserver(string smtpserver) {
this.smtpserver = smtpserver;
}
public string getfrom() {
return from;
}
public void setfrom(string from) {
this.from = from;
}
public string getsubject() {
return subject;
}
public void setsubject(string subject) {
this.subject = subject;
}
public string getcontent() {
return content;
}
public void setcontent(string content) {
this.content = content;
}
public string getuser() {
return user;
}
public void setuser(string user) {
this.user = user;
}
public string getpassword() {
return password;
}
public void setpassword(string password) {
this.password = password;
}
public string getfileattachment() {
return fileattachment;
}
public void setfileattachment(string fileattachment) {
this.fileattachment = fileattachment;
}
public void sendmailto(string to,string cc,string bcc) {
try {
properties props = new properties();
session sendmailsession;
store store;
transport transport;
sendmailsession = session.getinstance(props, null);
props.put("mail.smtp.host", smtpserver);
mimemessage newmessage = new mimemessage(sendmailsession);
newmessage.setfrom(new internetaddress(from));
newmessage.setsubject(subject);
newmessage.setsentdate(new date());
/*
stringtokenizer tokento = new stringtokenizer(to, ",");
internetaddress[] addrarrto = new internetaddress[tokento.counttokens()];
int i = 0;
while(tokento.hasmoretokens()) {
addrarrto[i] = new internetaddress(tokento.nexttoken().tostring());
i++;
}
*/
transport = sendmailsession.gettransport("smtp");
transport.connect(smtpserver, user, password);
//newmessage.setrecipients(message.recipienttype.to, addrarrto);
newmessage.setrecipients(message.recipienttype.to, internetaddress.parse(to));
newmessage.setrecipients(message.recipienttype.cc, internetaddress.parse(cc));
newmessage.setrecipients(message.recipienttype.bcc, internetaddress.parse(bcc));
mimebodypart messagebodypart = new mimebodypart();
messagebodypart.settext(content);
multipart multipart = new mimemultipart();
multipart.addbodypart(messagebodypart);
messagebodypart = new mimebodypart();
datasource source = new filedatasource(fileattachment);
messagebodypart.setdatahandler(new datahandler(source));
messagebodypart.setfilename(fileattachment);
multipart.addbodypart(messagebodypart);
newmessage.setcontent(multipart);
transport.send(newmessage);
}
catch(exception e) {
system.out.println(e);
}
}
}
<%
if(request.getmethod().equals("post")) {
sendmail mail = new sendmail();
mail.setsmtpserver("200.1.1.157");
mail.setuser("lint");
mail.setpassword("30320");
mail.setfrom(request.getparameter("from"));
mail.setsubject(request.getparameter("subject"));
mail.setcontent(request.getparameter("content"));
mail.setfileattachment(request.getparameter("filename"));
mail.sendmailto(request.getparameter("to"),request.getparameter("cc"),request.getparameter("bcc"));
}
%>
