Sending mail using JavaMail based on Java
1、 Related concepts of e-mail
Mail protocol. It mainly includes:
SMTP protocol: Simple Mail Transfer Protocol, which is used to send e-mail
POP3 protocol: post office protocol 3, the third version of post office protocol, is used to receive mail
IMAP protocol: Internet Message Access Protocol, that is, Internet Message Access Protocol, is an alternative protocol to POP3
--------------------------------------------------------------------------------
2、 Build James mail server
James is an open source project of Apache, a pure java implementation
Build James server
① Download apache-james-2.3 2. Zip decompression
② Run run. In the bin directory Bat to start the server [telnet localhost 4555]
③ Via apps \ James \ sar-inf \ config XML configuration server
Note: go to bin and run first. If the directory is not in Chinese, you have to open the telnet client on the control panel
--------------------------------------------------------------------------------
3、 Install outlook [mail client]
Product secret key: pqdv9-gpdv4-crm4d-phdth-4m2mt
Create user account
1、 Connect James' remote administration tool using telnet
2、 Log in as Administrator
3、 Use the addUser command to add users
--------------------------------------------------------------------------------
4、 Configure outlook mail client
To facilitate viewing, you can configure the Microsoft Outlook mail client to ensure that the James mail server is started and start Microsoft Outlook
Select tools - > options to open the options panel. Select "mail settings" and click "email account" to open the "account settings" panel. Create a new mail account under the email tab
--------------------------------------------------------------------------------
5、 Case [setting up James mail server]
Requirements Description:
Set up James mail server on this machine and customize the name of the server.
Create two test users.
Configure one of the test users in Microsoft Outlook as an outlook mail account
--------------------------------------------------------------------------------
6、 Sending e-mail using JavaMail (case)
Requirements:
JavaMail technology is used to send an e-mail from account a to account B, with the title of "meeting notice", and the content of the e-mail is "XX Hello! Please come to conference room B01 at 16:00 tomorrow afternoon on time to hold a technical seminar." Check whether the mail sent by the mail program is sent successfully through the outlook client
Key codes:
Create a class emailauthenticator, inherit from authenticator, and implant the user name and password
To create a mail class and set mail information:
Test class:
--------------------------------------------------------------------------------
7、 Send mail with attachments
Test class:
applicationContext. XML: large configuration
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.