*/voidsendAttachmentsMail(String receiveEmail,String subject,String emailContent,List<String>filePathList)throws MessagingException;} 4、创建IEmailService接口的实现类EmailService.java 文件 代码语言:javascript 复制 packagecom.springboot.email.email.service.impl;importcom.springboot.email.email.service.IEmail...
public class EmailController { private final EmailSpringUtil emailSpringUtil; @GetMapping("sendSpringEmail") public void sendSpringEmail(){ String subject = "这是一个测试标题"; String html = "统计数据如下所示:" + "\n" + " \n" + " 月度销售额\n" + " 年度销售额\n" + " \n" + "...
package com.springboot.email.email.service; import javax.mail.MessagingException; import java.util.List; public interface IEmailService { /** * 发送简单文本邮件 */ void sendSimpleMail(String receiveEmail, String subject, String content); /** * 发送HTML格式的邮件 */ void sendHtmlMail(String re...
由于Spring Boot的starter模块提供了自动化配置,所以在引入了spring-boot-starter-mail依赖之后,会根据配置文件中的内容去创建JavaMailSender实例,因此我们可以直接在需要使用的地方直接@Autowired来引入邮件发送对象。 对于qq邮箱这样写过后会报错: 1、异常信息: org.springframework.mail.MailSendException: Mail server con...
*/voidsendAttachmentsMail(String receiveEmail,String subject,String emailContent,List<String>filePathList)throws MessagingException;} 4、创建IEmailService接口的实现类EmailService.java 文件 packagecom.springboot.email.email.service.impl;importcom.springboot.email.email.service.IEmailService;importorg.springfr...
Test; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest public class MailServiceTest { @Autowired private MailService mailService; @Test public void testSendSimpleEmail() { assertTrue(mailService.sendSimpleEmail("test@example.com", "Test Subject", "This is a test email...
package com.springboot.email.email.service; import javax.mail.MessagingException; import java.util.List; public interface IEmailService { /** * 发送简单文本邮件 */ void sendSimpleMail(String receiveEmail, String subject, String content);
<name>email-springboot</name> <description>Demo project for Spring Boot</description> <properties> <java.version>8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <dependency> <...
mailService.sendSimpleMail(to, subject, content);return"Mail sent successfully"; } } 六、测试邮件发送功能 启动Spring Boot应用,访问以下URL测试邮件发送功能: http://localhost:8080/sendMail?to=recipient-email@gmail.com&subject=Test&content=This is atestemail. ...
* email:接收人的邮件地址, attachmentMap:附件的名称和文件路径] * @return: void * @Author: 你自己 * @Date: 2020/2/27 */publicvoidSendMimeEmail(String subject,String text,Boolean html,String email,Map<String,String>attachmentMap)throws MessagingException{JavaMailSenderImpl javaMailSender=JavaMailSende...