According to Ian F. darwin's "Java Cookbook" is compiled. The original book uses the entire chapter to describe how to send emails. The clues may be messy. In this article, we will condense it into an article, anyone who does not understand JavaMail can make slight modifications according to the instructions in this article. If you still have any questions about the principles, refer to the original book.
I. First, we need to use three java files:
1. The mnemonic of MailConstants. java and properties files:
//////////////////////////////////////// ///////////////////////////////
Package untitled2;
/** Simply a list of names for the Mail System to use.
* If you "implement" this interface, you don't have to prefix
* All the names with MailProps in your code.
*/
Public interface MailConstants {
Public static final String PROPS_FILE_NAME = "MailClient. properties ";
Public static final String SEND_PROTO = "Mail. send. protocol ";
Public static final String SEND_USER = "Mail. send. user ";
Public static final String SEND_PASS = "Mail. send. password ";
Public static final String SEND_ROOT = "Mail. send. root ";
Public static final String SEND_HOST = "Mail. send. host ";
Public static final String SEND_DEBUG = "Mail. send. debug ";
Public static final String RECV_PROTO = "Mail. receive. protocol ";
Public static final String RECV_PORT = "Mail. receive. port ";
Public static final String RECV_USER = "Mail. receive. user ";
Public static final String RECV_PASS = "Mail. receive. password ";
Public static final String RECV_ROOT = "Mail. receive. root ";
Public static final String RECV_HOST = "Mail. receive. host ";
Public static final String RECV_DEBUG = "Mail. receive. debug ";
}
//////////////////////////////////////// ///////////////////////////////
2. FileProperties. java, read properties from the file:
//////////////////////////////////////// ///////////////////////////////
Package untitled2;
Import java. io .*;
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.