Email reminder for secondary development of workflow

In order to consider the secondary development in the future, and the increase of the code in the future. Call the interface of the workflow, and write a lot of code in your own new project.

Workflow interface:

public boolean sendMail(Map lhm){
         //Set the URL address of the HTTP connection, which is the URL of the second application. If on the same computer you can change 192.168.1.134 to 127.0.0.1 or localhost  
        
        try {
            String http="http://localhost:8080/SDKFlow/email.action";
            URL url=new URL(http);  
            // Generate HttpURLConnection connection  
            HttpURLConnection httpurlconnection=(HttpURLConnection) url.openConnection();  
            //The output stream is set, the default is false, that is, parameters cannot be passed.  
            httpurlconnection.setDoOutput(true);  
            //Set the way to send the request. Note: Be sure to capitalize  
            httpurlconnection.setRequestMethod("POST");
            //Set the connection timeout time. However, if it is not set, in the case of abnormal network, it may cause the program to freeze and cannot continue to execute downward, so generally set a timeout time. in milliseconds  
            httpurlconnection.setConnectTimeout(30000);  
            //Set the output stream.  
            OutputStreamWriter writer=new OutputStreamWriter(httpurlconnection.getOutputStream(), "utf-8");  
            //The passed parameters are separated by & symbol.  
            writer.write("authid="+lhm.get("authid")+"&title="+lhm.get("title"));
            //Used to flush the buffer stream. Because by default, she will write to the buffer stream of the memory, and will only write when a certain amount of data is reached. Using this command allows him to write immediately, otherwise the stream will be closed  
            next writer.flush();  
            // It is used to close the output stream. After it is closed, data cannot be output, so use flush to flush the buffer stream  
            writer.close();  
            //Get the returned request.  
            int responseCode=httpurlconnection.getResponseCode();  


                System.out.println("OK"+responseCode);  
                //Get the output stream of the server. Get the returned data  
                InputStream urlstream=httpurlconnection.getInputStream();  
                BufferedReader reader=new BufferedReader(new InputStreamReader(urlstream));  
                String line;  
                String tline="";  
                while((line=reader.readLine())!=null) {  
                    tline+=line;  
                }  
                //Output all data  
                System.out.println(tline);  
                return true;
            }else{  
                System.out.println("ERR"+responseCode);  
            }  
        } catch (Exception e) {
            // TODO: handle exception
        }
        return false;
    }

My new project is composed of spring+mybatis.

controller class:

@RequestMapping(value="/email")
    public String Email(HttpServletRequest request, HttpServletResponse response)throws Exception{
        logger.info("进入邮件控制层");
        DataSourceContextHolder.setDbType("horizon");
        String authid=request.getParameter("authid");
        String title=request.getParameter("title");
//        String authid="HZ8080815fe7c0a7015febef32b10180";
//        String title="ss";
        String str=  sdkFlowService.GetUserEmailByUserID(authid,title);
        logger.info("返回值为:"+str);
        if(str.trim().equals("ok")){
            return "welcome";
        }else if(str.trim().equals("fail")){
            
            return "";
        }else{
            return "";
        }
        
    
    }

Interface implementation class:

/**
     * Get user information by user information ID
     * @param str User ID
     * @return user related information - get email
     * @throws Exception
     */
    @Transactional
    @Override
    public String GetUserEmailByUserID(String id,String title) throws Exception {
        logger.info("Enter Email interface");
        DBUserInfo user = new DBUserInfo();
        user.setID(id.trim());
        DBUserInfo userifno=sdkflowMapper.getUserEmail(user);
        if(userifno.getEMAIL()==null ||userifno.getEMAIL().equals("")){//If the email address is empty, return the string "fail"
            return "fail";
        }
        logger.info("Get the next node information: "+userifno);
        logger.info("Start sending mail");
        /////////////////////// /////////////////////////////////// Mailbox send mail
        Properties prop = new Properties();
        //Protocol
        prop.setProperty("mail.transport.protocol", "smtp");
        //Server
        prop.setProperty("mail.smtp.host", "smtp.exmail.qq.com");
        //Port
        prop .setProperty("mail.smtp.port", "465");
        //Use smtp authentication
        prop.setProperty("mail.smtp.auth", "true");
        //Use SSL, enterprise email is required!
        //Open the security protocol
        MailSSLSocketFactory sf = null;


            sf.setTrustAllHosts(true);
        } catch (GeneralSecurityException e1) {
            e1.printStackTrace();
        }
        prop.put("mail.smtp.ssl.enable", "true");
        prop.put("mail.smtp.ssl .socketFactory", sf);
        //
        //Get the Session object
        Session s = Session.getDefaultInstance(prop,new Authenticator() {
            //This request returns the object of the user and password
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication pa = new PasswordAuthentication("************.com", "******");
                return pa;
            }
        });
        //Set the debug mode of the session, cancel when publishing
        s.setDebug(true);
        MimeMessage mimeMessage = new MimeMessage(s);
        try {
            try {
                mimeMessage.setFrom(new InternetAddress("*****.com","* ****.com"));
                
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(userifno.getEMAIL() ));//Send an email to the specified person
            //Set the subject
            mimeMessage.setSubject(title);
            mimeMessage.setSentDate(new Date());
            //Set the content
            mimeMessage.setText("You have information to process, please click the link http://******/workflow");
            mimeMessage.saveChanges();
            //Send
            Transport.send(mimeMessage);
            return "ok" ;//Return "ok" on success
        } catch (MessagingException e) {
            e.printStackTrace();
        }
        return "fail";
    }
    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325834667&siteId=291194637