Java mail example

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.