HAP_邮箱发送

HAP_邮箱发送_第1张图片
image.png
HAP_邮箱发送_第2张图片
image.png

在html中定义个按钮

             <@spring.message "ora20796.sendEmail"/>

html添加事件函数


接口类:

package wht.ora20796.service;

import com.hand.hap.core.IRequest;
import com.hand.hap.core.ProxySelf;
import com.hand.hap.system.dto.ResponseData;
import com.hand.hap.system.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import wht.ora20796.dto.Ora20796Demo;
import wht.ora20796.mapper.Ora20796DemoMapper;

import java.util.List;

public interface IOra20796DemoService extends IBaseService, ProxySelf{

        /**
         *
         * @param request
         * @param dto
         * @param page
         * @param pageSize
         * @return
         */
        List selectUserById(IRequest request
                , Ora20796Demo dto, int page, int pageSize);

        /**
         * 定时任务
         */
        void updateRandomName(String prefix,Long id);

        /**
         * 邮箱发送
         */
        ResponseData sendEmail(IRequest iRequest)throws Exception;

}

实现类

   @Autowired
    private IMessageService messageService;
/**
     * 邮箱发送
     *
     * @param iRequest
     * @return
     * @throws Exception
     */
    @Override
    public ResponseData sendEmail(IRequest request) throws Exception {
        ResponseData responseData = new ResponseData();
        HashMap templateData = new HashMap();

        templateData.put("EMAIL_CONTENT", "This is a test email from Demo page");
        templateData.put("SENDER", request.getUserName());
        //收件人,可以有多人
        ArrayList receivers = new ArrayList<>();

        MessageReceiver messageReceiver = new MessageReceiver();
        messageReceiver.setMessageAddress("[email protected]");
        messageReceiver.setMessageType(ReceiverTypeEnum.NORMAL.getCode());
        receivers.add(messageReceiver);

        //messageService.sendMessage(request, "ACT_EMAIL_NOTIFIER", templateData, receivers, (List) null);
        messageService.sendMessage(request, "ORA_20796_DEMO", templateData, receivers, (List) null);

        return responseData;
    }

控制类:

    /**
     * 邮箱发送
     */
    @RequestMapping(value = "/hap/demo/send/email")
    @ResponseBody
    public ResponseData sendEmail(HttpServletRequest request) {
        IRequest iRequest = createRequestContext(request);
        ResponseData responseData = new ResponseData();
        try {
            responseData = service.sendEmail(iRequest);
        } catch (Exception e) {
            responseData.setSuccess(false);
            responseData.setMessage(e.getMessage());
        }
        return responseData;
    }
Failed to close server connection after message sending; nested exception is javax.mail.MessagingException: Exception reading response (java.net.SocketTimeoutException: Read timed out)
HAP_邮箱发送_第3张图片
image.png

你可能感兴趣的:(HAP_邮箱发送)