仓酷云

标题: JAVA编程:javamail发信的毗连SMTP考证的成绩 [打印本页]

作者: 若天明    时间: 2015-1-18 11:25
标题: JAVA编程:javamail发信的毗连SMTP考证的成绩
java比较简单,没有C++的烦琐,但学习时最好有C++为基础.与JSP和SQL起应用,功能强大.smtp|成绩MailBean.java

packagefastfox.util;
importjava.util.*;
importjava.text.SimpleDateFormat;
importjavax.mail.*;
importjavax.mail.internet.*;
importjavax.activation.*;
importjava.io.*;
publicclassMailBean{


publicstaticvoidsendMessage(StringsmtpHost,Stringfrom,Stringto,Stringsubject,StringmessageText)throwsMessagingException{
System.out.println("Configuringmailsessionfor:"+smtpHost);
SmtpAuthsa=newSmtpAuth();
sa.getuserinfo("jcren","mypassword");
java.util.Propertiesprops=newjava.util.Properties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtpHost);
System.out.println("Constructingmessage-from="+from+"to="+to);
InternetAddressfromAddress=newInternetAddress(from);
InternetAddress[]toAddresss=newInternetAddress[3];
toAddresss[0]=newInternetAddress("jcren@163.com");
toAddresss[1]=newInternetAddress("xxxxx@163.com");
toAddresss[2]=newInternetAddress("ccccc@163.com");
inti=0;
while(i<toAddresss.length){
SessionmailSession=Session.getDefaultInstance(props,sa);
MimeMessagetestMessage=newMimeMessage(mailSession);
testMessage.setFrom(fromAddress);
testMessage.addRecipient(javax.mail.Message.RecipientType.TO,toAddresss[i]);
testMessage.setSentDate(newjava.util.Date());
testMessage.setSubject(subject);
testMessage.setText(messageText);
System.out.println("Messageconstructed");

Transport.send(testMessage);
System.out.println("Messagesent!");
i++;
}
}

publicstaticvoidmain(String[]args){
StringsmtpHost="smtp.163.com";
Stringfrom="jcren@163.com";
Stringto="jcren@163.com";
Stringsubject="Testmessage";
StringBuffertheMessage=newStringBuffer();
theMessage.append("ddddhello22,

");
theMessage.append("Hopealliswellonyouend.
");
theMessage.append("Cheers");
try{
MailBean.sendMessage(smtpHost,from,to,subject,theMessage.toString());
}catch(javax.mail.MessagingExceptionexc){
exc.printStackTrace();
}
}

staticclassSmtpAuthextendsjavax.mail.Authenticator{
privateStringuser,password;

publicvoidgetuserinfo(Stringgetuser,Stringgetpassword){
user=getuser;
password=getpassword;
}
protectedjavax.mail.PasswordAuthenticationgetPasswordAuthentication(){
returnnewjavax.mail.PasswordAuthentication(user,password);
}
}
}
JSP援用:
<%@pagecontentType="text/html;charset=gb2312"import="java.util.*,java.sql.*"%>
<jsp:useBeanid="mailbean"scope="page"class="fastfox.util.MailBean"/>
<%
Stringmailto=request.getParameter("cust_mail");
Stringmailfrom="jcren@163.com";
StringSubject="Subject";
StringContent=request.getParameter("content");
mailbean.sendMessage("smtp.163.com",mailfrom,mailto,Subject,Content);
%>
JAVA是一种可以撰写跨平台应用软件的面向对象的程序设计语言,由升阳(SunMicrosystems)公司的詹姆斯·高斯林(JamesGosling)等人于1990年代初开发。
作者: 简单生活    时间: 2015-1-21 06:02
是一种将安全性(Security)列为第一优先考虑的语言
作者: 飘飘悠悠    时间: 2015-1-30 09:05
接着就是EJB了,EJB就是Enterprise JavaBean, 看名字好象它是Javabean,可是它和Javabean还是有区别的。它是一个体系结构,你可以搭建更安全、更稳定的企业应用。它的大量代码已由中间件(也就是我们常听到的 Weblogic,Websphere这些J2EE服务器)完成了,所以我们要做的程序代码量很少,大部分工作都在设计和配置中间件上。
作者: admin    时间: 2015-2-3 21:14
那么我书也看了,程序也做了,别人问我的问题我都能解决了,是不是就成为高手了呢?当然没那么简单,这只是万里长征走完了第一步。不信?那你出去接一个项目,你知道怎么下手吗,你知道怎么设计吗,你知道怎么组织人员进行开发吗?你现在脑子里除了一些散乱的代码之外,可能再没有别的东西了吧!
作者: 山那边是海    时间: 2015-2-9 05:05
Java是一个纯的面向对象的程序设计语言,它继承了 C++语言面向对象技术的核心。Java舍弃了C ++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)
作者: 莫相离    时间: 2015-2-13 09:49
一直感觉JAVA很大,很杂,找不到学习方向,前两天在网上找到了这篇文章,感觉不错,给没有方向的我指了一个方向,先不管对不对,做下来再说。
作者: 活着的死人    时间: 2015-2-28 22:40
[url]http://www.jdon.com/[/url]去下载,或到同济技术论坛的服务器[url]ftp://nro.shtdu.edu.cn[/url]去下,安装上有什么问题,可以到论坛上去提问。
作者: 愤怒的大鸟    时间: 2015-3-3 06:04
在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。
作者: 蒙在股里    时间: 2015-3-11 09:29
不过,每次的执行编译后的字节码需要消耗一定的时间,这同时也在一定程度上降低了 Java 程序的运行效率。
作者: 只想知道    时间: 2015-3-18 02:58
有时间再研究一下MVC结构(把Model-View-Control分离开的设计思想)
作者: 第二个灵魂    时间: 2015-3-25 10:05
另外编写和运行Java程序需要JDK(包括JRE),在sun的官方网站上有下载,thinking in java第三版用的JDK版本是1.4,现在流行的版本1.5(sun称作J2SE 5.0,汗),不过听说Bruce的TIJ第四版国外已经出来了,是专门为J2SE 5.0而写的。




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2