java邮箱实现忘记修改密码

一、spring-boot-starter-mail发送邮件(发送邮箱需要开启服务)
1.添加依赖

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

2.application.yml中配置

  mail:
    test-connection: true
    host: kkk.com
    port: 25
    username: 2222222.com
    password: 22222
    default-encoding: utf-8
    protocol: smtp
    emailFrom: 2222222.com

3.自定义配置类

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
 
@Component
@ConfigurationProperties(prefix = "spring.mail")
public class EmailConfig {
 
	private String emailFrom;
 
	public String getEmailFrom() {
		return emailFrom;
	}
 
	public void setEmailFrom(String emailFrom) {
		this.emailFrom = emailFrom;
	}
	
}

3.service代码

package com.pcr.user.service;

import javafx.util.Pair;

import java.io.File;
import java.util.List;

/**
 * @author zyn
 * @date now
 */
public interface EmailService {
    /**
     * 发送简单邮件
     * @param to 收件人地址
     * @param subject  邮件标题
     * @param content 邮件内容
     */
    public void sendSimpleMail(String[] to, String subject, String content);

    /**
     * 发送简单邮件
     * @param to 收件人地址
     * @param subject  邮件标题
     * @param content 邮件内容
     * @param attachments<文件名附件> 附件列表
     */
    public void sendAttachmentsMail(String[] to, String subject, String content, List<Pair<String, File>> attachments);


    /**
     * 发送html格式邮件
     * @param subject 主题
     * @param content 内容
     */
    public void sendHtmlMail(String to , String subject, String content);

//    /**
//     * 发送模板邮件
//     * @param to 收件人地址
//     * @param subject  邮件标题
//     * @param content<key内容> 邮件内容
//     * @param attachments<文件名附件> 附件列表
//     */
//    public void sendTemplateMail(String[] to, String subject, Map<String, Object> content, List<Pair<String, File>> attachments);
}
package com.pcr.user.service.impl;

import com.pcr.user.config.EmailConfig;
import com.pcr.user.service.EmailService;
import javafx.util.Pair;
import org.springframework.beans.factory.anno
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值