以下是我的代码
public class mailDemo {
public static void sendMail() {
String host = "smtp.yeah.net"; // 指定的smtp服务器
String from = "bllizard@yeah.net"; // 邮件发送人的邮件地址
String to = "13th-crow@163.com"; // 邮件接收人的邮件地址
final String username = "bllizard"; //发件人的邮件帐户
final String password = "007008"; //发件人的邮件密码
// 创建Properties 对象
Properties props = System.getProperties();
// 添加smtp服务器属性
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
// 创建邮件会话
Session session = Session.getDefaultInstance(props, new Authenticator(){ //验账账户
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
// 定义邮件信息
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));
message.setSubject("HelloWorld JavaMail");
message.setText("<a href='http://www.baidu.com'>Welcome to JavaMail World!</a>");
// 发送消息
//session.getTransport("smtp").send(message); //也可以这样创建Transport对象
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
mailDemo.sendMail();
}
}
以为这样可以再发送到邮箱的邮件中看到一个连接
可是在邮件中见到如下:
<a href=''http://www.baidu.com'>Welcome to JavaMail World!</a>
原封不动的打印出来了,有什么办法让他显示为一条连接呢?