疯狂的狮子li
2022-07-07 0b077806196ceb8a68af93f00880ccc70aee50c2
ruoyi-demo/src/main/java/com/ruoyi/demo/controller/MailController.java
@@ -2,9 +2,10 @@
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.email.MailUtils;
import io.swagger.annotations.Api;
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.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -14,41 +15,34 @@
/**
 * 测试邮件发送 Controller
 * 邮件发送案例
 *
 * @author Michelle.Chung
 */
@Validated
@Api(value = "邮件控制器", tags = {"测试邮件发送"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RequestMapping("/demo/mail")
@Tag(name ="邮件发送案例", description = "邮件发送案例")
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/mail")
public class MailController {
    /**
     * 发送邮件
     *
     * @param to      接收人
     * @param subject 标题
     * @param text    内容
     */
    @Operation(summary = "发送邮件")
    @GetMapping("/sendSimpleMessage")
    public R<Void> sendSimpleMessage(String to, String subject, String text) {
        MailUtils.send(to, subject, text, false);
        return R.ok("操作成功");
    public R<Void> sendSimpleMessage(@Parameter(name = "接收人") String to,
                                     @Parameter(name = "标题") String subject,
                                     @Parameter(name = "内容") String text) {
        MailUtils.sendText(to, subject, text);
        return R.ok();
    }
    /**
     * 发送邮件(带附件)
     *
     * @param to      接收人
     * @param subject 标题
     * @param text    内容
     */
    @Operation(summary = "发送邮件(带附件)")
    @GetMapping("/sendMessageWithAttachment")
    public R<Void> sendMessageWithAttachment(String to, String subject, String text, String filePath) {
        MailUtils.send(to, subject, text, false, new File(filePath));
        return R.ok("操作成功");
    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();
    }
}