jinlin
2024-01-31 9025b9cf7ec8610003d445a31d93e35e7bd73c2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.zt.modules.message.handler;
 
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import com.alibaba.fastjson.JSON;
import com.zt.common.message.handler.MessageHandler;
import com.zt.common.message.model.MessageContent;
import com.zt.common.message.model.MessageType;
import com.zt.common.message.model.identity.EmailIdentity;
import com.zt.common.message.model.identity.MessageIdentity;
 
/**
 * 邮件消息处理器。
 *
 * @author jeff
 */
@Component("bmp-mailHandler")
public class MailHandler extends MessageHandler<MessageContent> {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(MailHandler.class);
 
    @Override
    public MessageType getType() {
        return MessageType.EMAIL;
    }
 
    @Override
    public boolean getIsDefault() {
        return true;
    }
 
    @Override
    public boolean getSupportHtml() {
        return true;
    }
 
    @Override
    public boolean sendMessage(MessageContent notifMessage) {
        List<MessageIdentity> recievers = notifMessage.getReceivers();
        for (MessageIdentity reciever : recievers) {
            if (reciever instanceof EmailIdentity) {
                String email = ((EmailIdentity) reciever).getEmail();
                if (StringUtils.isNotBlank(email)) {
                    try {
                        // send(email, notifMessage.getSubject(), notifMessage.getHtmlContent());
 
                        // todo 调用邮件发送
                    } catch (Exception e) {
                        LOGGER.error("发送邮件失败!, 发送参数:{}", JSON.toJSONString(notifMessage), e);
                    }
                }
            }
        }
        LOGGER.debug("发送邮件成功 :{}", JSON.toJSONString(notifMessage));
        return true;
    }
 
}