|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
先说优点,首先和C,C++这些语言比起来,java很简单,去掉指针的java,非常好理解,自动垃圾回收机制也很好,自从JDK1.5推出以后,性能上又有了很大提高。/*
*Author:tyfun
*DateTime:2003.01.09
*Package:com.westarsoft.function
*/
packagecom.westarsoft.function;
importjava.util.*;
importjava.io.*;
importjavax.mail.*;
importjavax.mail.internet.*;
importjavax.activation.*;
publicclassSendMail{
privateStringSMTPServer=newString();
privateStringfrom=newString();
privateStringsubject=newString();
privateStringcontent=newString();
privateStringuser=newString();
privateStringpassword=newString();
privateStringfileAttachment=newString();
publicStringgetSMTPServer(){
returnSMTPServer;
}
publicvoidsetSMTPServer(StringSMTPServer){
this.SMTPServer=SMTPServer;
}
publicStringgetFrom(){
returnfrom;
}
publicvoidsetFrom(Stringfrom){
this.from=from;
}
publicStringgetSubject(){
returnsubject;
}
publicvoidsetSubject(Stringsubject){
this.subject=subject;
}
publicStringgetContent(){
returncontent;
}
publicvoidsetContent(Stringcontent){
this.content=content;
}
publicStringgetUser(){
returnuser;
}
publicvoidsetUser(Stringuser){
this.user=user;
}
publicStringgetPassword(){
returnpassword;
}
publicvoidsetPassword(Stringpassword){
this.password=password;
}
publicStringgetFileAttachment(){
returnfileAttachment;
}
publicvoidsetFileAttachment(StringfileAttachment){
this.fileAttachment=fileAttachment;
}
publicvoidsendMailTo(Stringto,Stringcc,Stringbcc){
try{
Propertiesprops=newProperties();
SessionsendMailSession;
Storestore;
Transporttransport;
sendMailSession=Session.getInstance(props,null);
props.put("mail.smtp.host",SMTPServer);
MimeMessagenewMessage=newMimeMessage(sendMailSession);
newMessage.setFrom(newInternetAddress(from));
newMessage.setSubject(subject);
newMessage.setSentDate(newDate());
/*
StringTokenizertokenTO=newStringTokenizer(to,",");
InternetAddress[]addrArrTO=newInternetAddress[tokenTO.countTokens()];
inti=0;
while(tokenTO.hasMoreTokens()){
addrArrTO[i]=newInternetAddress(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));
MimeBodyPartmessageBodyPart=newMimeBodyPart();
messageBodyPart.setText(content);
Multipartmultipart=newMimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart=newMimeBodyPart();
DataSourcesource=newFileDataSource(fileAttachment);
messageBodyPart.setDataHandler(newDataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);
newMessage.setContent(multipart);
transport.send(newMessage);
}
catch(Exceptione){
System.out.println(e);
}
}
}
<%
if(request.getMethod().equals("POST")){
SendMailmail=newSendMail();
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"));
}
%>
你精通任何一门语言就最强大。现在来看,java的市场比C#大,C#容易入手,比较简单,java比较难 |
|