二 SpringBoot - 核心配置文件( 四 )

7.1.4 application.yaml中写配置信息7.1.4.1application.yamlspring:mail:default-encoding: UTF-8host: smtp.qq.comport: 587username: xxxxxx@qq.compassword: 授权码7.1.4.2 请求方法@GetMapping("/sendEmail2")public String sendEmail2(@RequestParam(value = "https://www.huyubaike.com/biancheng/setToEmail",required = false) String setToEmail){SimpleMailMessage mailMessage = new SimpleMailMessage();mailMessage.setFrom("xxxxxx@qq.com"); //发送邮箱mailMessage.setTo("xxxxxx@qq.com"); //目标邮箱mailMessage.setText("你好 hello world");mailMessage.setSubject("测试 Springboot 邮箱服务");mailSender.send(mailMessage);return "====完成发送!====";}7.2 短信测试发送7.2.1 依赖<!-- SMS star --><dependency><groupId>com.aliyun</groupId><artifactId>dysmsapi20170525</artifactId><version>2.0.9</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea</artifactId><version>1.1.14</version></dependency><!-- SMS end -->7.2.2 代码其中:accessKeyId ,accessKeySecret 填写自己的用户 AccessKey,最好用子用户 AccessKey;
public class Sample {/*** 使用AK&SK初始化账号Client** @param accessKeyId* @param accessKeySecret* @return Client* @throws Exception*/public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()// 您的 AccessKey ID.setAccessKeyId(accessKeyId)// 您的 AccessKey Secret.setAccessKeySecret(accessKeySecret);// 访问的域名config.endpoint = "dysmsapi.aliyuncs.com";return new com.aliyun.dysmsapi20170525.Client(config);}public static void main(String[] args_) throws Exception {java.util.List<String> args = java.util.Arrays.asList(args_);com.aliyun.dysmsapi20170525.Client client = Sample.createClient("accessKeyId", "accessKeySecret");//accessKeyId ,accessKeySecret 填写自己的用户信息com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest().setSignName("阿里云短信测试").setTemplateCode("SMS_154950909").setPhoneNumbers("发送短信的手机号").setTemplateParam("{\"code\":\"131313\"}");com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();try {// 复制代码运行请自行打印 API 的返回值SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);} catch (TeaException error) {// 如有需要,请打印 errorString errerMsg = Common.assertAsString(error.message);} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);// 如有需要,请打印 errorString errorMsg = Common.assertAsString(error.message);}}}【二 SpringBoot - 核心配置文件】

经验总结扩展阅读