|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
那这个对象有什么意义?现在很多用javabean的人就不能保证对象有完整的意义,不成熟的使用模式等导致代码疯狂增长,调试维护的时间要得多得多。在说性能之前,先说说你这个比较的来历。据说微软为了证明。net网页编程比java好。
代码以下:
packagedemo;
importjava.util.Properties;
importjavax.activation.DataHandler;
importjavax.activation.DataSource;
importjavax.activation.FileDataSource;
importjavax.mail.BodyPart;
importjavax.mail.Message;
importjavax.mail.Multipart;
importjavax.mail.Session;
importjavax.mail.Transport;
importjavax.mail.internet.InternetAddress;
importjavax.mail.internet.MimeBodyPart;
importjavax.mail.internet.MimeMessage;
importjavax.mail.internet.MimeMultipart;
importsun.misc.BASE64Encoder;
publicclassMailSender...{
publicstaticvoidmain(String[]args)...{
MailSendersender=newMailSender();
sender.setHost("smtp.sina.com.cn");
sender.setFromAddr("");
sender.setToAddr("");
sender.setUsername("wwwwwwww");
sender.setPassword("ssssssss");
sender.setTitle("关于进步效力的几点设法");
sender.setAttachPath("C:singleUser.sql");
sender.setAttachName("singleUser.sql");
try...{
sender.sendMail();
}catch(Exceptione)...{
e.printStackTrace();
}
}
publicvoidsendMail()throwsException...{
Propertiesprops=newProperties();
props.put("mail.smtp.host",getHost());
props.put("mail.smtp.auth","true");
Sessionsession=Session.getDefaultInstance(props);
session.setDebug(true);
MimeMessagemessage=newMimeMessage(session);
message.setFrom(newInternetAddress(getFromAddr()));
message.addRecipient(Message.RecipientType.TO,newInternetAddress(getToAddr()));
message.setSubject(getTitle());
Multipartmultipart=newMimeMultipart();
BodyPartcontentPart=newMimeBodyPart();
contentPart.setText("邮件的详细内容在此");
multipart.addBodyPart(contentPart);
if(getAttachPath()!=null&&getAttachName()!=null)...{
BodyPartattachmentPart=newMimeBodyPart();
DataSourcesource=newFileDataSource(getAttachPath());
attachmentPart.setDataHandler(newDataHandler(source));
BASE64Encoderenc=newBASE64Encoder();
attachmentPart.setFileName("=?GBK?B?"+enc.encode(getAttachName().getBytes())+"?=");
multipart.addBodyPart(attachmentPart);
}
message.setContent(multipart);
message.saveChanges();
Transporttransport=session.getTransport("smtp");
transport.connect(host,getUsername(),getPassword());
transport.sendMessage(message,message.getAllRecipients());
transport.close();
}
privateStringhost=null;
privateStringfromAddr=null;
privateStringtoAddr=null;
privateStringusername=null;
privateStringpassword=null;
privateStringtitle=null;
privateStringattachPath=null;
privateStringattachName=null;
publicStringgetHost()...{
returnhost;
}
publicvoidsetHost(Stringhost)...{
this.host=host;
}
publicStringgetFromAddr()...{
returnfromAddr;
}
publicvoidsetFromAddr(StringfromAddr)...{
this.fromAddr=fromAddr;
}
publicStringgetToAddr()...{
returntoAddr;
}
publicvoidsetToAddr(StringtoAddr)...{
this.toAddr=toAddr;
}
publicStringgetUsername()...{
returnusername;
}
publicvoidsetUsername(Stringusername)...{
this.username=username;
}
publicStringgetPassword()...{
returnpassword;
}
publicvoidsetPassword(Stringpassword)...{
this.password=password;
}
publicStringgetTitle()...{
returntitle;
}
publicvoidsetTitle(Stringtitle)...{
this.title=title;
}
publicStringgetAttachPath()...{
returnattachPath;
}
publicvoidsetAttachPath(StringattachPath)...{
this.attachPath=attachPath;
}
publicStringgetAttachName()...{
returnattachName;
}
publicvoidsetAttachName(StringattachName)...{
this.attachName=attachName;
}
}
JAVA学习必须明确这是一项投资,对于大多数的人来说,学习JAVA是为了就业,还有就是刚走向工作位置的朋友想尽快赶上工作的节奏。 |
|