邮件任务实现

1、添加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

2、开启邮箱(这边使用的是126,QQ等其它同理)

在这里插入图片描述

3、application.properties配置

# 你的邮箱/或者一般企业中有一个公共使用的邮箱
spring.mail.username=xxxxx@126.com
# 使用上面给的授权密码
spring.mail.password=JXSUIDHJWYQNZXHE
#QQ的话是 smtp.qq.com   163: smtp.163.com
spring.mail.host=smtp.126.com
#QQ的话还需要开启加密验证
#spring.mail.properties.mail.smtp.ssl.enable=true

4、实现

@SpringBootTest
class DemoApplicationTests {

    @Autowired
    JavaMailSenderImpl mailSender;

    @Test
    void contextLoads() {
        // 简单例子
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject("主题内容测试");
        simpleMailMessage.setText("测试212121212");
        simpleMailMessage.setTo("xxx@126.com");
        simpleMailMessage.setFrom("xxx@126.com");
        mailSender.send(simpleMailMessage);
    }

}

在这里插入图片描述

@SpringBootTest
class DemoApplicationTests {

    @Autowired
    JavaMailSenderImpl mailSender;

    @Test
    void contextLoads() throws MessagingException {
        // 一个复杂的邮件
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        //组装
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        helper.setSubject("复杂内容测试");
        helper.setText("<p style='color:red'>复杂内容测试</p>",true);
        helper.addAttachment("1.jpg",new File("C:\\Users\\Admin\\Pictures\\Saved Pictures\\1.jpg"));
        helper.setTo("xxx@126.com");
        helper.setFrom("xxx@126.com");

        mailSender.send(mimeMessage);
    }

}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flowable中的邮件任务是一种特殊的服务任务,用于在业务流程中发送电子邮件。您可以通过设置服务任务的类型为"mail"来定义邮件任务邮件任务可以增强业务流程,包括支持抄送、密送、HTML内容等功能。需要注意的是,邮件任务不是BPMN 2.0规范的正式任务,因此在Flowable中,它被实现一个专门的服务任务。 以下是一个示例,演示如何在Flowable中配置邮件任务: ```xml <serviceTask id="sendMail" flowable:type="mail"> <!-- 配置邮件服务器 --> <extensionElements> <flowable:field name="host"> <flowable:string><![CDATA[smtp.example.com]]></flowable:string> </flowable:field> <flowable:field name="port"> <flowable:string><![CDATA[587]]></flowable:string> </flowable:field> <flowable:field name="username"> <flowable:string><![CDATA[username@example.com]]></flowable:string> </flowable:field> <flowable:field name="password"> <flowable:string><![CDATA[password]]></flowable:string> </flowable:field> <flowable:field name="starttls"> <flowable:string><![CDATA[true]]></flowable:string> </flowable:field> </extensionElements> <!-- 配置邮件内容 --> <extensionElements> <flowable:field name="to"> <flowable:string><![CDATA[recipient@example.com]]></flowable:string> </flowable:field> <flowable:field name="subject"> <flowable:string><![CDATA[Hello]]></flowable:string> </flowable:field> <flowable:field name="text"> <flowable:string><![CDATA[This is the email body.]]></flowable:string> </flowable:field> </extensionElements> </serviceTask> ``` 在上述示例中,我们首先配置了邮件服务器的相关信息,包括主机、端口、用户名、密码和是否启用STARTTLS。然后,我们配置了邮件的收件人、主题和正文内容。 请注意,上述示例仅用于演示目的,实际使用时需要根据您的邮件服务器和业务需求进行相应的配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值