Java program for email

xiaoxiao2021-03-06  106

The following is an example of an email HTML for you to write an email reference. The function is HTML to the mail to send the UL address. The images will be sent together with the mail .Package com.fswan.Memo; Import Java.IO. IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Properties Import java.util.Regex.matcher; import java.util.regex.pattern;

import javax.activation.DataHandler; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; / ** * @author swan Fong (Fang Zhiwen) * * / Public class testmail {public static final string ul = "http://www.qxzw.com/htmpage/0/14/123.htm"; public static void main (string [] args) {try {url url = new url (UL); // INPUTSTREAM INS = url.openStream (); sendmail (URL, "Newsbot@yeah.net", "smtp.yeah.net");} catch (Malformedurlexcection E) {E.PrintStackTrace ();} } public static void sendMail (URL url, String mail, String smtpServer) {System.out.println ( "send"); MimeMultipart mp = new MimeMultipart ();. String idStr = new SimpleDateFormat ( "hhmmsss") format (new Date ()); System.out.println (IDSTR); try {i NPUTSTREAM INS = url.openStream (); stringbuffer sb = new stringbuffer (); byte [] cons = new byte [10240]; int Len = INS.READ (conts); while (len> 0) {sb.append (new String (conts, 0, len); // system.out.println (new string (cons)); // cons = new byte [10240]; len = INS.READ (conts);} string con = SB. Tostring (); string con2 = sb.toString (); sb = new stringbuffer (); string regex = "] *) /"?. * /? / / s *> "; pattern p = pattern.Compile (regex); matcher m = p.matcher (con); arraylist _mailattachment = new arraylist (); int lastpos = 0;

转载请注明原文地址:https://www.9cbs.com/read-99012.html

New Post(0)