Skip to content

minsx framework common mail

Joker edited this page Apr 4, 2018 · 2 revisions

Minsx-framework-common-mail

主要功能
  •  整合阿里/腾讯/网易/谷歌等各大企业邮箱及个人邮箱服务器配置
  •  仅需给定用户名与密码即可完成邮箱服务器配置
  •  可根据需要选择是否开启SSL发送邮件
  •  支持普通文本邮件
  • 支持HTML邮件
  • 支持任意附件邮件
  • 支持批量发送邮件
  •  内置系统模板
  •  可自定义模板
极简的配置
import com.minsx.framework.common.mail.MailSender;
import com.minsx.framework.common.mail.MailSenderFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EmailConfig {

    @Bean
    public MailSender getMailSender() {
        return MailSenderFactory.getTencentEnterpriseSSLSender("yourUsername", "yourPassword");
    }

}
极简的使用
import com.minsx.framework.common.mail.MailSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MailUtil {

    @Autowired
    MailSender mailSender;

    public void sendMail(String to, String title, String content) {
        mailSender.sendSimpleMail(to,title,content);
    }

}
系统模板使用
import com.minsx.framework.common.mail.MailSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class MailUtil {

    @Autowired
    MailSender mailSender;

    public Boolean sendMail(String to, String username, String title, String content) {
        Boolean isSuccess = true;
        Map<String, Object> params = new HashMap<>();
        params.put("headerLogo", "https://image.minsx.com/pic/minsx/logo/LogoOfWhite.png");
        params.put("footerLogo", "https://image.minsx.com/pic/minsx/logo/logoSuperGray.png");
        params.put("webSite", "https://www.minsx.com/");
        params.put("webName", "米斯云平台");
        params.put("welcome", String.format("尊敬的%s:", username));

        params.put("content", content);
        params.put("company", "米斯云平台");
        params.put("remind", "该邮件由米斯云平台系统发出,请勿直接回复!");
        params.put("copyRight", "如果您有任何问题,请及时联系我们:\nEmail: support@minsx.com\nCopyright © 2016-2017 minsx.com All rights reserved.");
        params.put("date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        try {
            mailSender.sendSysTemplateMail(to, title, params);
        } catch (Exception e) {
            e.printStackTrace();
            isSuccess = false;
        }
        return isSuccess;
    }

}
系统模板效果

0

Maven依赖使用请参考
  • POM引入:
<dependency>
  <groupId>com.minsx</groupId>
  <artifactId>minsx-framework-common-mail</artifactId>
  <version>1.0.0</version>
</dependency>

Minsx-framework

项目文档
联系方式
Clone this wiki locally