Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ The Java utility, JavaMail     - C language keywords Comments (Programming)

- [Android] Eclipse does not update the Android SDK Manager solution [using GoAgent] (Programming)

- To assign multiple IP addresses NIC on the CentOS 7 (Linux)

- Using monitoring tool dsniff (Linux)

- Oracle 12c users create (Database)

- Mongo-connector integrated MongoD to achieve incremental Solr index (Server)

- Linux file permissions to modify the command: chmod (Linux)

- The method of Linux into the rescue mode (Linux)

- Amazon EC2 server using Rsync + Inotify real-time synchronization (Server)

- Ubuntu 14.04 install Sublime Text 3 plug and use SublimeClang (Linux)

- Linux virtual machine how to access the Internet in a virtual machine when using NAT mode (Linux)

- Linux processes in memory and memory cgroup statistics (Linux)

- About Linux iptables firewall interview questions and answers (Linux)

- Setup Qt development environment under Linux (Linux)

- Lazarus for Raspbian installation (Linux)

- JBPM6 Installation and Configuration Tutorial (Linux)

- Zabbix API and PHP configuration (Server)

- Hadoop namenode do NFS disaster recovery (Server)

- CentOS 7 install Hadoop-cdh-2.6 (Server)

- C ++ string in the end (Programming)

 
         
  The Java utility, JavaMail
     
  Add Date : 2017-08-31      
         
         
         
  In the realization of javamail first to build e-mail server.

James

In the process of WEB development need to use Tomcat server, but the Tomcat server does not support the mail processing operation, so in order to send mail, you also need to configure a separate Java Mail server, James is an enterprise-class mail server, It fully implements SMTP (Simple Mail Transfer Protocol) and POP3 (Post Office Protocol 3, the third version of the Post Office Protocol) and NNTP (Network News Transport Protocol) protocol. At the same time, James server is a mail application platform. It allows users to easily implement a very powerful e-mail application. Readers can use the Apache's James server, direct landing http://james.apache.org/, download the James server.

In the online search can be configured directly to the James server, a large number of blog can refer to, I do not cumbersome to repeat here, it is worth noting that:

There is a hit during configuration
Telnet localhost 4555

No response to the needs of the control panel -> Programs and Features -> open or close the windows feature to open the Telnet service can be

JavaMail introduction and configuration

JavaMail is a set of specifications for Java that handles e-mail handling. It can be used to send mail easily, or you can use JavaMail to develop applications similar to Microsoft Outlook.

JavaMail core categories:
1.javax.mail.Session: that the entire message of the session, all classes have to be used through the session;
2.javax.mail.Message: Message class that is the content of the message delivery;
3.javax.mail.Address: When OK Session and Message, you can send address through the specified address;
4.javax.mail. Authenticator: Use this class to protect resources by user name and password;
5.javax.mail.Transport: This message is used in the last step of sending this class, the function of this class is to use the specified language to send messages;
6.javax.mail.Store: This class is mainly for information read, write and other operations, you can also read through the folder of such messages;
7.javax.mail.Folder: used for hierarchical management of the message.

Example: Send an ordinary message

Send mail to rely on the previously configured James server and JavaMail (JAF) class to complete, but in the mail sent, it must be noted that, because now all the mailbox users are stored in the James server, so be sure to first write a An action class that can be used to validate the user name and password for the server, which must inherit from the javax.mail.Authenticator class and override the getPasswordAuthentication () method.

< % @ Page contentType = "text / html; charset = GBK" language = "java"%>
< Html>
< Head>
< Title> Send E-mail < / title> in plain text format
< Meta http-equiv = "Content-Type" content = "text / html; charset = GBK">
< Link href = "css / style.css" rel = "stylesheet">
< Script language = "javascript">
Function checkform (myform) {
    For (i = 0; i < myform.length; i ++) {
        If (myform.elements [i] .value == "")) {
            Alert (myform.elements [i] .title + "can not be empty!");
            Myform.elements [i] .focus ();
            Return false;
        }}
    }}
}}
< / Script>
< / Head>
< Body>
< Form name = "form1" method = "post" action = "mydeal.jsp" onSubmit = "return checkform (form1)">
< Table width = "588" height = "360" border = "0" align = "center" cellpadding = "0" cellspacing = "0" background = "images / bg.jpg">
  < Tr>
    < Td width = "60" height = "73" background = "Images / board_left.gif" & nbsp; < / td>
    < Td width = "486" background = "Images / board_left.gif"> & nbsp; < / td>
    < Td width = "46" background = "Images / board_left.gif"> & nbsp; < / td>
  < / Tr>
  < Tr valign = "top">
    < Td height = "247"> & nbsp; < / td>
    < Td valign = "top"> < table width = "96%" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
      < Tr>
        < Td width = "16%" height = "27" align = "center"> To: < / td>
        < Td width = "84%" colspan = "2" align = "left"> < input name = "to" type = "text" id = "to" title = "recipient" size = "60"> < / Td>
      < / Tr>
      < Tr>
        < Td height = "27" align = "center"> From: < / td>
        < Td colspan = "2" align = "left"> < input name = "from" type = "text" id = "from" title = "sender" size = "60"> < / td>
      < / Tr>
      < Tr>
        < Td height = "27" align = "center"> Secret & nbsp; & nbsp; Code: < / td>
        < Td colspan = "2" align = "left"> < input name = "password" type = "password" id = "password" title = "Frombox Password" size = "60"> < / td>
      < / Tr>
      < Tr>
        < Td height = "27" align = "center"> main & nbsp; & nbsp; title: < / td>
        < Td colspan = "2" align = "left"> < input name = "subject" type = "text" id = "subject" title = "message subject" size = "60"> < / td>
      < / Tr>
      < Tr>
        < Td height = "93" align = "center"> Inside & nbsp; & nbsp; Contains: < / td>
        < Td colspan = "2" align = "left"> < textarea name = "content" cols = "59" rows = "7" class = "wenbenkuang" id = "content" title = "message content"> < / textarea > < / Td>
      < / Tr>
      < Tr>
        < Td height = "30" align = "center"> & nbsp; < / td>
        < Td height = "40" align = "right"> < input name = "Submit" type = "submit" class = "btn_bg" value = "Send">
          & Nbsp;
          < Input name = "Submit2" type = "reset" class = "btn_bg" value = "reset">
          & Nbsp;
          < Input name = "Submit3" type = "button" class = "btn_bg" onClick = "window.close ();" value = "Close">
          & Nbsp; & nbsp; & nbsp; < / td>
        < Td align = "left"> & nbsp; < / td>
      < / Tr>
    < / Table> < / td>
    < Td> & nbsp; < / td>
  < / Tr>
  < Tr valign = "top">
    < Td height = "40"> & nbsp; < / td>
    < Td> & nbsp; < / td>
    < Td> & nbsp; < / td>
  < / Tr>
< / Table>
< / Form>
< / Body>
< / Html>

 

Mydeal.jsp

 

< % @ Page contentType = "text / html; charset = GBK" language = "java" errorPage = ""%>
< % @ Page import = "java.util. *"%>
< % @ Page import = "javax.mail. *"%>
< % @ Page import = "javax.mail.internet. *"%>
< % @ Page import = "javax.activation. *"%>
< % @ Page import = "org.apache.commons.mail. *"%>
< %
Try {
    Request.setCharacterEncoding ( "GBK");
    String from = request.getParameter ( "from");
    String to = request.getParameter ( "to");
    String subject = request.getParameter ( "subject");
    String messageText = request.getParameter ( "content");
    String password = request.getParameter ( "password");
    String mailserver = "localhost"; / / LAN to send mail when the SMTP server
    SimpleEmail email = new SimpleEmail ();
    Email.setHostName (mailserver); // Set up the mail server
    Email.setAuthentication (from, password); / / set the mailbox user name and password
    Email.setFrom (from); // Set the sender address
    Email.addTo (to); / / set the recipient address
    Email.setSubject (subject); // Set the theme
    Email.setSentDate (new Date ()); / / set the send time
    Email.setMsg (messageText); // Set the sent message
    Email.send (); // Send the message
      Out.println ( "< script language = 'javascript'> alert ( 'message has been sent!'); Window.location.href = 'index.jsp'; < / script>");
} Catch (Exception e) {
    E.printStackTrace ();
    System.out.println ( "send mail generated error:" + e.getMessage ());
    Out.println ( "< script language = 'javascript'> alert ( 'message failed!'); Window.location.href = 'index.jsp'; < / script>");
}}
%>

Need to guide the package: mail.jar
     
         
         
         
  More:      
 
- VPN built on CentOS (Server)
- How to view the Linux program or process used in the library (Linux)
- How to manage Vim plugin (Linux)
- After installing minimize RHEL / CentOS 7 need to do some things (Linux)
- Java Database Programming JDBC configuration (Programming)
- Port is not being used, how will bind failure? (Server)
- CentOS 6.5 boot automatically mount the hard drive (Linux)
- Analysis of Java exception (Programming)
- Ubuntu 14.04 and derivative versions of the user install Pantheon Photos 0.1 (Linux)
- Java MD5 encryption implementation (Programming)
- Five Linux user space debugging tool (Linux)
- Python variable type (Programming)
- Oracle11g CRS-0184 Problem Solving (Database)
- Ubuntu 14.04.1 LTS compile and install the new kernel (Linux)
- Close common port to protect server security (Linux)
- Install NetBeans IDE 8.0 on Ubuntu, Linux Mint, Elementary OS, and Debian (Linux)
- Install Websphere MB required system rpm package under Linux (Linux)
- Ubuntu 14.04 How to install Cinnamon 2.4.5 (Linux)
- MySQL rollback insert statement causes ibd file grows double (Database)
- Android 4.2 compilation notes (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.