在html中定义个按钮
<span class="btn btn-success k-grid-save-changes" data-bind="click:save" style="float:left;margin-right:5px;"><@spring.message "ora20796.sendEmail"/></span>
html添加事件函数
<script type="text/javascript">
var viewModel = Hap.createGridViewModel("#grid",{
sendEmail:function () {
$.ajax({
url: '${base.contextPath}/wht/ora/20796/student/send/email',
type: 'POST',
dataType: "json",
contentType: "application/json",
success: function (result) {
if(result.success){
kendo.ui.showInfoDialog({
title: $l('hap.tip.info'),
message: $l("hap.success")
});
viewModel.query();
} else {
kendo.ui.showErrorDialog({
title: $l('hap.error'),
message : result.message
});
}
}
});
}
});
</script>
接口类:
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<Ora20796Demo>, ProxySelf<IOra20796DemoService>{
/**
*
* @param request
* @param dto
* @param page
* @param pageSize
* @return
*/
List<Ora20796Demo> 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<String, Object> templateData = new HashMap<String, Object>();
templateData.put("EMAIL_CONTENT", "This is a test email from Demo page");
templateData.put("SENDER", request.getUserName());
//收件人,可以有多人
ArrayList<MessageReceiver> receivers = new ArrayList<>();
MessageReceiver messageReceiver = new MessageReceiver();
messageReceiver.setMessageAddress("shizhou.cui@hand-china.com");
messageReceiver.setMessageType(ReceiverTypeEnum.NORMAL.getCode());
receivers.add(messageReceiver);
//messageService.sendMessage(request, "ACT_EMAIL_NOTIFIER", templateData, receivers, (List<Long>) null);
messageService.sendMessage(request, "ORA_20796_DEMO", templateData, receivers, (List<Long>) 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)