易截截图软件、单文件、免安装、纯绿色、仅160KB

smtp of java mail

send mail use smtp .u can send text or html, send to many peoples if u have a email user and pwd and the smtp of the email which u use.
package org.lc.smtp;
import java.io.IOException;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.util.ByteArrayDataSource;
import com.sun.mail.smtp.SMTPTransport;
/**
* smtp send mail.
* @author lc.
*/
public class smtp {
Message message;
Properties properties = new Properties();
Session session;
/**
*
* @param from mail from
* @param pwd mail pwd
* @param host mail from smtp host
* @param to to someone's mail
*/
public smtp(String from, String pwd, String host, String to) throws MessagingException, IOException {
properties.put("mail.smtp.host", host);// set smtp properties
session = Session.getInstance(properties);
message = new MimeMessage(session);
message.setSubject("title of mail");// set titile
message.setText("text");//send text
message.setDataHandler(new DataHandler(new ByteArrayDataSource("<a href="\" mce_href="\""http://www.baidu.com\">ahaha..</a>".toString(), "text/html")));// send html
message.setfrom(new InternetAddress(from));// set send from
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,false));// set send where

SMTPTransport t = (SMTPTransport) session.getTransport("smtp");
t.connect(host, from, pwd);
t.sendMessage(message, message.getAllRecipients());
}

public static void main(String[] args) throws Exception {
new smtp(args[0], args[1], args[2], args[3]);
}

}


相关文档:

利用JAVA向Oracle数据库中插入大对象

通过JDBC,我们可以向oracle插入大对象,如图片,音频,长文本等,其插入方法有很多,这里演示一下通过流更新更新的形式插入CLOB大对象。
这是一个存储文本的例子,解释我会在程序中以注释的形式写出
/**
  * 将生成的表样存储到数据库
  *
  * @param htmlParam
  * @return
  */
  ......

JAVA中的位移操作 >> >>

中小
Java中共有三个移位操作符,分别是:
<<:左移操作,所有操作数向左移动,每移一位最右边用0补充
>>:带符号位右移:连同符号位一起右移,每移一位最左边用符号位补充
>>>:无符号右移:连同符号位一起右移,每移一位最左边用0补充
移位操作符只能作用于整数类型,即byte,short,char,i ......

java读取properties属性文件值方法

在使用hibernate或者spring的时候,我们往往通过配置文件配置数据库连接属性。但这次项目中并没有用到hibernate和spring,只用到了struts2。要如何实现通过读取文件配置获取属性值呢?ResourceBundle这个类可是实现读取properties文件来获取值
在java中:
public final static Object initLock = new Object();
privat ......

JAVA读取外部资源的方法

在java代码中经常有读取外部资源的要求:如配置文件等等,通常会把配置文件放在classpath下或者在web项目中放在web-inf下.
1.从当前的工作目录中读取:
        try {
            BufferedReader in = new BufferedReader(new InputStreamRea ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号