📄 htmlmail.jsp
字号:
<%@page contentType="text/html"%>
<%@page pageEncoding="Ms950"%>
<%@page import ="java.util.*,java.io.*"%>
<%@page import ="javax.mail.*"%>
<%@page import ="javax.mail.internet.*"%>
<%@page import ="javax.activation.*"%>
<html>
<head><title>发送 HTML 格式邮件</title></head>
<body>
<%
Properties theProperties = System.getProperties() ;
theProperties.put("mail.host","127.0.0.1") ;
theProperties.put("mail.transport.protocol","smtp") ;
Session theSession =
Session.getDefaultInstance(theProperties,null) ;
theSession.setDebug(false) ;
MimeMessage theMessage = new MimeMessage(theSession) ;
theMessage.setFrom
(new InternetAddress("coffee@fj.com") ) ;
theMessage.setRecipients
(Message.RecipientType.TO,"tea@fj.com") ;
theMessage.setSubject("JavaMail HTML 格式邮件") ;
MimeBodyPart theMimeBodyPart0 = new MimeBodyPart() ;
String bodyMessage =
"<font size=7>JSP JavaMail HTML 格式邮件 </font>";
theMimeBodyPart0.setContent
(bodyMessage,"text/html;charset=Ms950") ;
String theFileName = request.getRealPath
("/"+"ch11//htmlMail//htmlFile.htm") ;
FileDataSource theFileDataSource= new
FileDataSource(theFileName) ;
MimeBodyPart theMimeBodyPart = new MimeBodyPart() ;
theMimeBodyPart.setDataHandler
(new DataHandler(theFileDataSource)) ;
theMimeBodyPart.setFileName(theFileDataSource.getName()) ;
String theFileName1=request.getRealPath
("/"+"ch11//htmlMail//images.jpg") ;
FileDataSource theFileDataSource1= new
FileDataSource(theFileName1) ;
MimeBodyPart theMimeBodyPart1 = new MimeBodyPart() ;
theMimeBodyPart1.setDataHandler
(new DataHandler(theFileDataSource1)) ;
theMimeBodyPart1.setHeader("Content-ID","rpic") ;
Multipart theMultipart = new MimeMultipart("related");
theMultipart.addBodyPart(theMimeBodyPart0) ;
theMultipart.addBodyPart(theMimeBodyPart) ;
theMultipart.addBodyPart(theMimeBodyPart1) ;
theMessage.setContent(theMultipart) ;
Transport.send(theMessage) ;
out.println("成功发送邮件!!") ;
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -