In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of what is the method of JavaMail sending HTML mail, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this JavaMail method of sending HTML email, let's take a look at it.
Form.htm
=
SMTP host: sender: addressee: CC: messenger: topic: content:
Send.jsp
=
Pipi.jaf.StringDatasource.java
= =
Package pipi.jaf
Public class StringDataSource implements javax.activation.DataSource {
Private java.lang.String data
Private java.lang.String type
Public StringDataSource (java.lang.String data,java.lang.String type) {
This.data = data
This.type = type
}
Public java.io.InputStream getInputStream () throws java.io.IOException {
Return new java.io.StringBufferInputStream (data)
}
Public java.io.OutputStream getOutputStream () throws java.io.IOException {
Throw new java.io.IOException ("it does not support this method now!")
}
Public java.lang.String getContentType () {
Return type
}
Public java.lang.String getName () {
Return "pipi"
}
}
Pipi.mail.HTML.java
=
Package pipi.mail
Public final class HTML {
Public static void send (
Java.lang.String smtp, / * SMTP host address * /
Java.lang.String from, / * sender * /
Java.lang.String to, / * recipient * /
Java.lang.String cc, / * CC * /
Java.lang.String bcc, / * send it to someone in secret * /
Java.lang.String subject, / * theme * /
Java.lang.String body / * content * /
) throws java.lang.Exception {
/ / variable declaration
Java.util.Properties props; / / system Properties
Javax.mail.Session mailSession; / / Mail session object
Javax.mail.internet.MimeMessage mimeMsg; / / MIME mail object
/ / set system properties
Props = java.lang.System.getProperties (); / / get the system property object
Props.put ("mail.smtp.host", smtp); / / set the SMTP host
/ / get the mail session object
MailSession = javax.mail.Session.getDefaultInstance (props,null)
/ / create a MIME mail object
MimeMsg = new javax.mail.internet.MimeMessage (mailSession)
/ / set the sender
MimeMsg.setFrom (new javax.mail.internet.InternetAddress (from))
/ / set the recipient
If (topless null) {
MimeMsg.setRecipients (javax.mail.Message.RecipientType.TO,javax.mail.internet.InternetAddress.parse (to))
}
/ / set up CC.
If (cclockwise null) {
MimeMsg.setRecipients (javax.mail.Message.RecipientType.CC,javax.mail.internet.InternetAddress.parse (cc))
}
/ / set the message to someone.
If (BCC invalid null) {
MimeMsg.setRecipients (javax.mail.Message.RecipientType.BCC,javax.mail.internet.InternetAddress.parse (bcc))
}
/ / set the subject of the message
/ / mimeMsg.setSubject (subject)
MimeMsg.setSubject (subject, "gb2312")
/ / set the content of the message
MimeMsg.setDataHandler (new javax.activation.DataHandler (new pipi.jaf.StringDataSource (body, "text/html")
/ / send email
Javax.mail.Transport.send (mimeMsg)
}
}
This program uses JavaMail and JAVABEANS (TM) ACTIVATION framework (JAF):
JavaMail
Http://java.sun.com/products/javamail/
JAVABEANS (TM) ACTIVATION FRAMEWORK (JAF)
Http://java.sun.com/products/javabeans/glasgow/jaf.html
This is the end of the article on "what is the method for JavaMail to send HTML mail". Thank you for reading! I believe you all have a certain understanding of the knowledge of "what is the method of sending HTML mail by JavaMail". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.