问题描述
我正在使用 JavaMailSender
类通过 SMTP 协议向 Microsoft Teams 频道添加新消息。它工作正常,但我需要创建公告而不是默认对话消息。有什么办法可以实现吗?
我正在使用 spring 框架和 JavaMailSenderImpl 类向团队发送消息。也许我应该添加一些标题或类似的东西来发送公告,而不是对话消息?
@requiredArgsConstructor
@Slf4j
public class DefaultTeamsService implements TeamsService{
private final JavaMailSender mailSender;
@Value("${app.mail.from}")
private String from;
@Override
public void sendMessage(String to,String subject,String html) {
try {
MimeMessage message = formMessage(from,to,subject,html);
mailSender.send(message);
} catch (MessagingException e) {
log.error("Failed to form message",e);
}
}
private MimeMessage formMessage(String from,String to,String html) throws MessagingException {
MimeMessage message = mailSender.createMimeMessage();
message.setSubject("","utf-8");
MimeMessageHelper helper = new MimeMessageHelper(message,true,"UTF-8");
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(html,true);
return message;
}