疯狂的狮子li
2022-07-07 0b077806196ceb8a68af93f00880ccc70aee50c2
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
package com.ruoyi.demo.controller;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.email.MailUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
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
@Tag(name ="邮件发送案例", description = "邮件发送案例")
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/mail")
public class MailController {
 
    @Operation(summary = "发送邮件")
    @GetMapping("/sendSimpleMessage")
    public R<Void> sendSimpleMessage(@Parameter(name = "接收人") String to,
                                     @Parameter(name = "标题") String subject,
                                     @Parameter(name = "内容") String text) {
        MailUtils.sendText(to, subject, text);
        return R.ok();
    }
 
    @Operation(summary = "发送邮件(带附件)")
    @GetMapping("/sendMessageWithAttachment")
    public R<Void> sendMessageWithAttachment(@Parameter(name = "接收人") String to,
                                             @Parameter(name = "标题") String subject,
                                             @Parameter(name = "内容") String text,
                                             @Parameter(name = "附件路径") String filePath) {
        MailUtils.sendText(to, subject, text, new File(filePath));
        return R.ok();
    }
 
}