First, download the package activation. jar and mail. jar.
DetailsCodeAs follows:
Package alogrim; </P> <p> Import Java. util. date; <br/> Import Java. util. properties; </P> <p> Import javax. mail. session; <br/> Import javax. mail. transport; <br/> Import javax. mail. internet. internetaddress; <br/> Import javax. mail. internet. mimemessage; </P> <p> public class Sendmail {</P> <p> // ���� <br/> Public static void send () throws exception {<br/> properties props = system. getproperties (); // returns the value of this parameter. <Br/> props. put ("mail. SMTP. host "," smtp.163.com "); <br/> props. put ("mail. SMTP. auth "," true "); <br/> session = session. getdefaultinstance (props, null); <br/> mimemessage MSG = new mimemessage (session); </P> <p> internetaddress [] tolist = internetaddress. parse ("2004369701@163.com", false); <br/> MSG. addrecipients (mimemessage. recipienttype. to, tolist); </P> <p> internetaddress fromaddress = new Internet Address ("2004369701@163.com"); <br/> MSG. setfrom (fromaddress); <br/> MSG. setsentdate (new date (); </P> <p> MSG. setsubject ("mail", "ISO-2022-JP"); <br/> string TXT = "Hello test mail OK? "; <Br/> MSG. settext (txt, "ISO-2022-JP"); </P> <p> transport T = session. gettransport ("SMTP"); <br/> T. connect ("smtp.163.com", "mailbox name", "Mailbox password"); <br/> T. sendmessage (MSG, tolist ); <br/>}</P> <p>/** <br/> * @ Param ARGs <br/> * @ throws exception <br/> */<br/> Public static void main (string [] ARGs) throws exception {<br/> // todo auto-generated method stub <br/> send (); <br/>}</P> <p >}< br/>
The following exception may be reported:
Exception: noclassdeffounderror: COM/Sun/activation/registries/logsupport
Solution:
The first problem is to delete Java ee 5 libraries/javaee. Jar/mail.
The second problem is to delete Java ee 5 libraries/javaee. Jar/activation. Then download the latest activation. jar from the Internet.
How to delete:
Use RAR to open D:/myeclipse 7.0/genuitec/common/plugins/COM. genuitec. eclipse. j2eedt. core_7.0.0.zmyeclipse70020081206/data/libraryset/ee_5/javaee. jar, open it with a compressed package, and find the folder you want to delete.