[code="java"][/code]/*
* Created on 2009-1-8
*/
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* @author gjg
*/
public class SenderWithSMTPVer {
String host = "82.0.191.1";
/**
*
* @param from
* 发件人的地址
* @param to
* 收件人地址
* @param titleMsg
* 邮件标题
*/
public void sendMail(String from, String to, String titleMsg) {
Properties props = new Properties();
props.put("mail.smtp.host", host);// 指定SMTP服务器
props.put("mail.smtp.auth", "false");// 指定是否需要SMTP验证,为false时,不用指定用户名、密码
try {
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);// 是否在控制台显示debug信息
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));// 发件人
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));// 收件人
// 将中文转化为GB2312编码
message.setSubject(titleMsg, "GB2312"); // 邮件主题
message.setContent("<a href='http://www.qq.com'>请点击此链接!</a>",
"text/html;charset=gb2312");// 邮件内容
message.saveChanges();
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, null, null);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
SenderWithSMTPVer sm = new SenderWithSMTPVer();
sm.sendMail("abc@sohu.com", "kjc_zh/xj/ccb@ccb", "Test Mail!");
}
}
* Created on 2009-1-8
*/
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* @author gjg
*/
public class SenderWithSMTPVer {
String host = "82.0.191.1";
/**
*
* @param from
* 发件人的地址
* @param to
* 收件人地址
* @param titleMsg
* 邮件标题
*/
public void sendMail(String from, String to, String titleMsg) {
Properties props = new Properties();
props.put("mail.smtp.host", host);// 指定SMTP服务器
props.put("mail.smtp.auth", "false");// 指定是否需要SMTP验证,为false时,不用指定用户名、密码
try {
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);// 是否在控制台显示debug信息
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));// 发件人
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));// 收件人
// 将中文转化为GB2312编码
message.setSubject(titleMsg, "GB2312"); // 邮件主题
message.setContent("<a href='http://www.qq.com'>请点击此链接!</a>",
"text/html;charset=gb2312");// 邮件内容
message.saveChanges();
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, null, null);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
SenderWithSMTPVer sm = new SenderWithSMTPVer();
sm.sendMail("abc@sohu.com", "kjc_zh/xj/ccb@ccb", "Test Mail!");
}
}