jsp javamail发送html邮件

<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*,javax.mail.*,javax.mail.internet.*"
 pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>extjs examples</title>
  <!-- copy right guoXXXXX.iteye.com -->
 </head>
 <body>
 <p>
  <div id="my_id">&nbsp;</div>
 </p>
 </body>
</html>
<%
String   to   ="XXXXX@xmcu.cn";  
              String   from   ="XXXXX@xmcu.cn";  
              String   server="mail.xmcu.cn";  
              String   user="XXXXX";  
              String   password="XXXXX2009";  
               
              try{  
              Properties   props=new   Properties   ();  
              props.put("mail.smtp.host",server);  
              props.put("mail.smtp.auth","true");  
              props.put("mail.bebug","true");  
   
              //URLName   urlName=new   URLName(server);  
              //PasswordAuthentication   pa=new   PasswordAuthentication(user,password);  
              Session   sendMailSession=Session.getDefaultInstance(props,null);  
              sendMailSession.setDebug(true);  
   
              //sendMailSession.setPasswordAuthentication   (urlName,pa);  
              //SMTPTransport   transport=new   SMTPTransport(sendMailSession,null);  
              Transport   transport=sendMailSession.getTransport("smtp");  
              Message   msg   =   new   MimeMessage(sendMailSession);  
              msg.setFrom(new   InternetAddress(from));  
              InternetAddress[]   address   =   {new   InternetAddress(to)};  
          msg.setRecipients(Message.RecipientType.TO,   address);  
              msg.setSubject("您好,请审批");  
              //msg.setHeader("X-Mailer",   "msgsend");  
              msg.setSentDate(new   Date());  
              Multipart mp = new MimeMultipart();
   MimeBodyPart mbp = new MimeBodyPart();
      
   // 设定邮件内容的类型为 text/plain 或 text/html
   mbp.setContent("<a href='http://test.com/sdfj?sfsfjeijflskjdflsjdf' target='blank'>审批</a>","text/html;charset=GB2312");
   mp.addBodyPart(mbp);
   msg.setContent(mp);

             // msg.setText   ("<a href='fsdf'>asfsaf</a>");  
   
              transport.connect   (server,user,password);  
              //transport.connect   ();  
              transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));  
              }  
              catch(Exception   ex){  
                  ex.printStackTrace();  
              }  

 

%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值