疯狂的狮子Li
2022-05-02 4941aaa5c1c59f17881d3587f1679b93736bd01e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.ruoyi.demo.controller;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.email.MailUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.File;
 
 
/**
 * 邮件发送案例
 *
 * @author Michelle.Chung
 */
@Validated
@Api(value = "邮件发送案例", tags = {"邮件发送案例"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RequestMapping("/demo/mail")
@RestController
public class MailController {
 
    @ApiOperation("发送邮件")
    @GetMapping("/sendSimpleMessage")
    public R<Void> sendSimpleMessage(@ApiParam("接收人") String to,
                                     @ApiParam("标题") String subject,
                                     @ApiParam("内容") String text) {
        MailUtils.sendText(to, subject, text);
        return R.ok();
    }
 
    @ApiOperation("发送邮件(带附件)")
    @GetMapping("/sendMessageWithAttachment")
    public R<Void> sendMessageWithAttachment(@ApiParam("接收人") String to,
                                             @ApiParam("标题") String subject,
                                             @ApiParam("内容") String text,
                                             @ApiParam("附件路径") String filePath) {
        MailUtils.sendText(to, subject, text, new File(filePath));
        return R.ok();
    }
 
}