The JavaMail API is an optional package (standard extension) for reading, writing, and sending electronic messages that can be used to establish standards-based e-mail clients that configure various Internet mail messages, including SMTP, POP, IMAP, and MIME, as well as related NNTP, S/MIME and other agreements. It is often necessary to develop javamail programs with the Sun's JavaBeans activation Framework (JAF). The operation of the JavaBeans activation framework is complex, which simply means that JavaMail's operation must depend on its support, such as JavaMail using JavaBeans activation framework To handle MIME-encoded message attachments. The JavaMail interface is contained in Javax.mail and its child packages, and the JavaBeans activation Framework interface is contained in the Javax.activation package, and the JAF specification is "Glasgow" JavaBeans For more details on JAF, please refer to the JAF guide:
Http://java.sun.com/beans/glasgow/jaf.html
The core JavaMail API consists of seven classes: Session, message, address, authenticator, transport, Store, and Folder, all from Javax.mail, the JavaMail API The top-level package. You can use these classes to accomplish a large number of common e-mail tasks, including sending messages, retrieving messages, deleting messages, authenticating, replying to messages, forwarding messages, managing attachments, processing messages based on HTML file formats, and searching or filtering mailing lists. For more information about JavaMail, refer to the JavaMail guide:
http://java.sun.com/products/javamail/
Similar to the JavaMail implementation of the SendMail program, there are many online. But the author found that most of them have a problem. My code is down there. Please make sure your machine has been installed JDK1.4 javamial1.3.2 and JAF before the mode is ready. If it is not installed, install the following steps:
1 Get the latest JDK from the www.java.sun.com website. Then set the Java environment variables.
If it is win95/98, add the following 3 line statements at the end of \autoexec.bat:
java_home=c:\j2sdk1.4.2
path=%java_home%\bin;%path%
Classpath=.; %java_home%\lib
Watch the Classpath first ".", this represents the current directory, many people HelloWorld not run up most of this is the reason.
If it is Win2000 or XP, use the mouse to right-click the "My Computer"-> Properties-> advanced-> Environment variables
System variable-> new-> variable name: Java_home variable Value: c:\j2sdk1.4.2
System variable-> edit-> variable name: Path at the front of the variable value plus:%java_home%\bin;
System variable-> new-> variable name: CLASSPATH variable value:.; %java_home%\lib\tools.jar;%java_home%\lib\dt.jar;
The one in front of the Classpath "." Is the same as the above meaning.
Please mode a HelloWorld to verify the installation is successful?
2 http://java.sun.com/products/javamail/Download the latest javamail.
Set Classpath=%classpath%;c:\download\javamail-1.3.2\mail.jar;.
Set Classpath=%classpath%;c:\download\activation\activation.jar
4 OK. Finally, I can catch my breath first. Next, start the program section. Return the IF (Themail.setto ("########") = False) to the #号改为你自己的邮箱 in. Then return if (Themail.addfileaffix ("#######") = = False); In #写为本地的一个文件路径. can also be empty. For more people to learn, please do not modify the sendMail@163.com password: sendcode This mailbox only in the program test use!!
And then, in DOS,
Javac Sendmail.java
Java SendMail
Hehe Successful!!! My host DOS display
D:\>java SendMail
Set System Properties: Mail.smtp.host = smtp.163.com
Prepare to get mail Session Object!
Prepare to create MIME mail Object!
Set SMTP identity authentication: Mail.smtp.auth = True
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.