要服务网站建设,哈尔滨ui设计培训学校,如何创建一个app,厦门做网站优化的公司目录 引出springboot整合email配置邮箱导入依赖application.yml配置email业务类测试类 springboot整合阿里云短信服务申请阿里云短信服务测试短信服务获取阿里云的accessKeyspringboot整合阿里云短信导包工具类 总结 引出 1.springboot整合email#xff0c;qq邮箱#xff0c;… 目录 引出springboot整合email配置邮箱导入依赖application.yml配置email业务类测试类 springboot整合阿里云短信服务申请阿里云短信服务测试短信服务获取阿里云的accessKeyspringboot整合阿里云短信导包工具类 总结 引出 1.springboot整合emailqq邮箱特点免费 2.springboot整合阿里短信服务100条免费 3.后续应用可以用在登陆业务上比如邮箱登陆短信登陆
springboot整合email
配置邮箱 登录邮箱服务器 登录QQ邮箱 后面要用到这个授权码key 导入依赖
!-- qq邮箱--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-mail/artifactId/dependencyapplication.yml配置 email业务类 接口 package com.tianju.auth.service;public interface IEmailService {/*** 发送右键* param to 邮件接收方* param subject 邮件主题* param content 邮件内容*/void sendEmail(String to,String subject,String content);
} 实现 package com.tianju.auth.service.impl;import com.tianju.auth.service.IEmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;import javax.annotation.Resource;
import java.util.Date;Service
Slf4j
public class EmailServiceImpl implements IEmailService {Value(${spring.mail.username})private String from;Resourceprivate JavaMailSender javaMailSender;Overridepublic void sendEmail(String to, String subject, String content) {SimpleMailMessage mailMessage new SimpleMailMessage();mailMessage.setSubject(subject);mailMessage.setTo(to);mailMessage.setText(content);mailMessage.setSentDate(new Date());mailMessage.setFrom(from);javaMailSender.send(mailMessage);log.debug(在{}发送一条邮件{}给{},mailMessage.getSentDate(),mailMessage.getText(),mailMessage.getTo());}
}测试类
package com.tianju.auth.service.impl;import com.tianju.auth.service.IEmailService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import javax.xml.ws.soap.Addressing;import java.util.UUID;import static org.junit.Assert.*;SpringBootTest
RunWith(SpringJUnit4ClassRunner.class)
public class EmailServiceImplTest {Autowiredprivate IEmailService emailService;Testpublic void sendEmail() {emailService.sendEmail(xxxxqq.com, 我是老王我在测试代码, UUID.randomUUID().toString());}
}springboot整合阿里云短信服务
申请阿里云短信服务
短信服务 (aliyun.com) 测试短信服务 进行测试 调用结果 成功接收短信 获取阿里云的accessKey springboot整合阿里云短信
导包 !-- 阿里云短信验证码相关包--dependencygroupIdcom.aliyun/groupIdartifactIdaliyun-java-sdk-core/artifactIdversion4.5.3/version/dependency工具类
package com.tianju.auth.util;import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import net.minidev.json.JSONObject;import java.util.HashMap;
import java.util.Map;
import java.util.Random;public class SMSUtil {private static String AccessIdKey 获取的keyID;private static String AccessKeySecret 获取的KeySecret;public static void send(String tel,String code) {DefaultProfile profile DefaultProfile.getProfile(cn-hangzhou,AccessIdKey, //AccessIdKeyAccessKeySecret); //AccessKey SecretIAcsClient client new DefaultAcsClient(profile);CommonRequest request new CommonRequest();request.setSysMethod(MethodType.POST);//下面这3个不要改动request.setSysDomain(dysmsapi.aliyuncs.com);request.setSysVersion(2017-05-25);request.setSysAction(SendSms);//接收短信的手机号码request.putQueryParameter(PhoneNumbers,tel);//此处写电话号码//短信签名名称request.putQueryParameter(SignName,阿里云短信测试);//短信模板IDrequest.putQueryParameter(TemplateCode,SMS_154950909);//短信模板变量对应的实际值 ${code} 中的值MapString,String param new HashMap(2);param.put(code, String.valueOf(code)); //写入的短信内容,验证码request.putQueryParameter(TemplateParam, JSONObject.toJSONString(param));try {CommonResponse response client.getCommonResponse(request);System.out.println(response.getData());} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}}public static void main(String[] args) {int i new Random().nextInt(80000) 10000;System.out.println(i); // 35054SMSUtil.send(xxxx, 392712);}} 总结
1.springboot整合emailqq邮箱特点免费 2.springboot整合阿里短信服务100条免费 3.后续应用可以用在登陆业务上比如邮箱登陆短信登陆 文章转载自: http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.ktsth.cn.gov.cn.ktsth.cn http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn http://www.morning.tgfjm.cn.gov.cn.tgfjm.cn http://www.morning.gbkkt.cn.gov.cn.gbkkt.cn http://www.morning.fmrd.cn.gov.cn.fmrd.cn http://www.morning.xplng.cn.gov.cn.xplng.cn http://www.morning.ljsxg.cn.gov.cn.ljsxg.cn http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn http://www.morning.mnrqq.cn.gov.cn.mnrqq.cn http://www.morning.gwdnl.cn.gov.cn.gwdnl.cn http://www.morning.bxrlt.cn.gov.cn.bxrlt.cn http://www.morning.lbxcc.cn.gov.cn.lbxcc.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.rszbj.cn.gov.cn.rszbj.cn http://www.morning.tndxg.cn.gov.cn.tndxg.cn http://www.morning.czxrg.cn.gov.cn.czxrg.cn http://www.morning.ailvturv.com.gov.cn.ailvturv.com http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn http://www.morning.prqdr.cn.gov.cn.prqdr.cn http://www.morning.ldspj.cn.gov.cn.ldspj.cn http://www.morning.jbctp.cn.gov.cn.jbctp.cn http://www.morning.jtkfm.cn.gov.cn.jtkfm.cn http://www.morning.xptkl.cn.gov.cn.xptkl.cn http://www.morning.wmfr.cn.gov.cn.wmfr.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.qxlgt.cn.gov.cn.qxlgt.cn http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn http://www.morning.rybr.cn.gov.cn.rybr.cn http://www.morning.cldgh.cn.gov.cn.cldgh.cn http://www.morning.zbjfq.cn.gov.cn.zbjfq.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.rpms.cn.gov.cn.rpms.cn http://www.morning.pplxd.cn.gov.cn.pplxd.cn http://www.morning.qinhuangdjy.cn.gov.cn.qinhuangdjy.cn http://www.morning.kgjyy.cn.gov.cn.kgjyy.cn http://www.morning.pmsl.cn.gov.cn.pmsl.cn http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.lsfbb.cn.gov.cn.lsfbb.cn http://www.morning.tlnbg.cn.gov.cn.tlnbg.cn http://www.morning.grbgn.cn.gov.cn.grbgn.cn http://www.morning.wtwhj.cn.gov.cn.wtwhj.cn http://www.morning.fqtdz.cn.gov.cn.fqtdz.cn http://www.morning.kjtdy.cn.gov.cn.kjtdy.cn http://www.morning.tkchg.cn.gov.cn.tkchg.cn http://www.morning.touziyou.cn.gov.cn.touziyou.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.pbsqr.cn.gov.cn.pbsqr.cn http://www.morning.xdpjs.cn.gov.cn.xdpjs.cn http://www.morning.mxhcf.cn.gov.cn.mxhcf.cn http://www.morning.jsxrm.cn.gov.cn.jsxrm.cn http://www.morning.ctsjq.cn.gov.cn.ctsjq.cn http://www.morning.mfqmk.cn.gov.cn.mfqmk.cn http://www.morning.wspjn.cn.gov.cn.wspjn.cn http://www.morning.mmqhq.cn.gov.cn.mmqhq.cn http://www.morning.mbfkt.cn.gov.cn.mbfkt.cn http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn http://www.morning.dkbsq.cn.gov.cn.dkbsq.cn http://www.morning.ngcw.cn.gov.cn.ngcw.cn http://www.morning.xzsqb.cn.gov.cn.xzsqb.cn http://www.morning.fwblh.cn.gov.cn.fwblh.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.tkcct.cn.gov.cn.tkcct.cn http://www.morning.rykn.cn.gov.cn.rykn.cn http://www.morning.pqryw.cn.gov.cn.pqryw.cn http://www.morning.btpzn.cn.gov.cn.btpzn.cn http://www.morning.ycnqk.cn.gov.cn.ycnqk.cn http://www.morning.tfkqc.cn.gov.cn.tfkqc.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.pwmm.cn.gov.cn.pwmm.cn http://www.morning.wrtpk.cn.gov.cn.wrtpk.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.znqmh.cn.gov.cn.znqmh.cn http://www.morning.fthcq.cn.gov.cn.fthcq.cn http://www.morning.nkwgy.cn.gov.cn.nkwgy.cn