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]);
}
}
相关文档:
前些天和一个C++程序员聊天时,聊到一些对象、数组存储空间时,由于两人都不是大鸟,之前也看过一些java存储数据的资料,但都是过目便忘。也没有进行总结过。下面是转载过来,感觉总结的很全面。
java对象内存机制:http://java.chinait ......
线程
1---锁对象的方法----obj.wait()----obj.notify()----针对当前线程
& ......
中小
Java中共有三个移位操作符,分别是:
<<:左移操作,所有操作数向左移动,每移一位最右边用0补充
>>:带符号位右移:连同符号位一起右移,每移一位最左边用符号位补充
>>>:无符号右移:连同符号位一起右移,每移一位最左边用0补充
移位操作符只能作用于整数类型,即byte,short,char,i ......
Java配置文件读取有各种不同的文件,但是由于打包Jar后的路径改变,往往在项目中能正确读取的配置文件在Jar后变成文件不存在的杯具,下在提出几各不同的配置文件读取方式,仅供参考
一、直接文件读取
File f = new File("you config file path");
FileReader fr = new FileReader(f);
BufferReader br = new ......
好久没用java,突一写起来,发现机器上没有设置环境变量,把设置方法总结一下
1. 修改/etc/profile文件
如果你的计算机仅仅作为开发使用时推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,可能会给系统带来安全性问题。
·用文本编辑器打开/etc/profile
·在pr ......