Skip to content

Commit

Permalink
feat: 支持动态邮件
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jun 5, 2024
1 parent 94168e2 commit 1dbb339
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.continew.admin.system.config.mail;

import cn.hutool.core.map.MapUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.continew.admin.common.constant.SysConstants;
import top.continew.admin.system.service.OptionService;
import top.continew.starter.messaging.mail.core.MailConfig;
import top.continew.starter.messaging.mail.core.MailConfigService;

import java.util.Map;

/**
* 邮件配置实现
*
* @author Charles7c
* @since 2024/5/30 22:32
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class MailConfigServiceImpl implements MailConfigService {

private final OptionService optionService;

@Override
public MailConfig getMailConfig() {
// 查询邮件配置
Map<String, String> map = optionService.getByCategory("MAIL");
// 封装邮件配置
MailConfig mailConfig = new MailConfig();
mailConfig.setProtocol(MapUtil.getStr(map, "MAIL_PROTOCOL"));
mailConfig.setHost(MapUtil.getStr(map, "MAIL_HOST"));
mailConfig.setPort(MapUtil.getInt(map, "MAIL_PORT"));
mailConfig.setUsername(MapUtil.getStr(map, "MAIL_USERNAME"));
mailConfig.setPassword(MapUtil.getStr(map, "MAIL_PASSWORD"));
mailConfig.setSslEnabled(SysConstants.YES.equals(MapUtil.getInt(map, "MAIL_SSL_ENABLED")));
if (mailConfig.isSslEnabled()) {
mailConfig.setSslPort(MapUtil.getInt(map, "MAIL_SSL_PORT"));
}
return mailConfig;
}
}

0 comments on commit 1dbb339

Please sign in to comment.