MyMailNotifier.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //package com.yihu.admin.email;
  2. //
  3. //import de.codecentric.boot.admin.event.ClientApplicationEvent;
  4. //import de.codecentric.boot.admin.notify.MailNotifier;
  5. //import org.slf4j.Logger;
  6. //import org.slf4j.LoggerFactory;
  7. //import org.springframework.boot.context.properties.ConfigurationProperties;
  8. //import org.springframework.expression.EvaluationContext;
  9. //import org.springframework.expression.Expression;
  10. //import org.springframework.expression.ParserContext;
  11. //import org.springframework.expression.spel.standard.SpelExpressionParser;
  12. //import org.springframework.expression.spel.support.StandardEvaluationContext;
  13. //import org.springframework.mail.MailSender;
  14. //import org.springframework.mail.SimpleMailMessage;
  15. //import org.springframework.stereotype.Component;
  16. //
  17. //import java.util.Arrays;
  18. //
  19. ///**
  20. // * Created by chenweida on 2018/5/8 0008.
  21. // * de.codecentric.boot.admin.config.NotifierConfiguration */
  22. //@Component
  23. //@ConfigurationProperties("spring.boot.admin.notify.mail")
  24. //public class MyMailNotifier extends MailNotifier {
  25. //
  26. //
  27. // private static final String DEFAULT_SUBJECT = "#{application.name} (#{application.id}) is #{to.status}";
  28. // private static final String DEFAULT_TEXT = "#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}";
  29. //
  30. // private final SpelExpressionParser parser = new SpelExpressionParser();
  31. //
  32. // private Logger logger = LoggerFactory.getLogger(MyMailNotifier.class);
  33. //
  34. // private final MailSender sender;
  35. //
  36. // /**
  37. // * recipients of the mail
  38. // */
  39. // private String to[] = {"root@localhost"};
  40. //
  41. // /**
  42. // * cc-recipients of the mail
  43. // */
  44. // private String cc[];
  45. //
  46. // /**
  47. // * sender of the change
  48. // */
  49. // private String from = null;
  50. //
  51. // /**
  52. // * Mail Text. SpEL template using event as root;
  53. // */
  54. // private Expression text;
  55. //
  56. // /**
  57. // * Mail Subject. SpEL template using event as root;
  58. // */
  59. // private Expression subject;
  60. //
  61. // public MyMailNotifier(MailSender sender) {
  62. // super(sender);
  63. // logger.info("init email");
  64. // this.sender = sender;
  65. // this.subject = parser.parseExpression(DEFAULT_SUBJECT, ParserContext.TEMPLATE_EXPRESSION);
  66. // this.text = parser.parseExpression(DEFAULT_TEXT, ParserContext.TEMPLATE_EXPRESSION);
  67. //
  68. // }
  69. //
  70. // @Override
  71. // protected void doNotify(ClientApplicationEvent event) {
  72. // logger.info("send email");
  73. // EvaluationContext context = new StandardEvaluationContext(event);
  74. //
  75. // SimpleMailMessage message = new SimpleMailMessage();
  76. // message.setTo(to);
  77. // message.setFrom(from);
  78. // message.setSubject(subject.getValue(context, String.class));
  79. // message.setText(text.getValue(context, String.class));
  80. // message.setCc(cc);
  81. //
  82. // sender.send(message);
  83. // }
  84. //
  85. // public void setTo(String[] to) {
  86. // this.to = Arrays.copyOf(to, to.length);
  87. // }
  88. //
  89. // public String[] getTo() {
  90. // return Arrays.copyOf(to, to.length);
  91. // }
  92. //
  93. // public void setCc(String[] cc) {
  94. // this.cc = Arrays.copyOf(cc, cc.length);
  95. // }
  96. //
  97. // public String[] getCc() {
  98. // return Arrays.copyOf(cc, cc.length);
  99. // }
  100. //
  101. // public void setFrom(String from) {
  102. // this.from = from;
  103. // }
  104. //
  105. // public String getFrom() {
  106. // return from;
  107. // }
  108. //
  109. // public void setSubject(String subject) {
  110. // this.subject = parser.parseExpression(subject, ParserContext.TEMPLATE_EXPRESSION);
  111. // }
  112. //
  113. // public String getSubject() {
  114. // return subject.getExpressionString();
  115. // }
  116. //
  117. // public void setText(String text) {
  118. // this.text = parser.parseExpression(text, ParserContext.TEMPLATE_EXPRESSION);
  119. // }
  120. //
  121. // public String getText() {
  122. // return text.getExpressionString();
  123. // }
  124. //}