package com.gear.common.utils.slemail; import cn.hutool.crypto.SecureUtil; import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.json.JSONUtil; import java.time.LocalDateTime; import java.time.ZoneId; //20240507之前的,邮件发送,后来过期了 public class SLSendEimailUtils { public static void sendEmail(String toUser,String title,String code) { final String baseUrl = "https://api.itniotech.com/email"; final String apiKey = "CVgLCtpUVtJaPnfwSqDR4KHQmqjfBRdM"; final String apiPwd = "5iUa6NNji65nmF88WF2ENdXUgMK4ePBV"; final String appId = "UZawLaxM"; final String fromEmailAddress = "sax@mail.saxtrader.cc"; // The Mail address configured in the ITNIO final String toAddress = toUser; //Recipient Address final String subject = title; //Send Message Subject final String templateID = "1001342"; //Send Template ID final String templateData = "{\"code\":\""+code+"\"}"; //Template variable parameters final int adFlag = 0; //Whether to add the advertising logo final String language = "en"; //language final boolean checkEmailAddress = false; //Enable email address validity check final int isUnsubscribe = 0; final String url = baseUrl.concat("/sendEmail"); HttpRequest request = HttpRequest.post(url); // currentTime final String datetime = String.valueOf(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond()); // generate md5 key final String sign = SecureUtil.md5(apiKey.concat(apiPwd).concat(datetime)); request.header(Header.CONNECTION, "Keep-Alive") .header(Header.CONTENT_TYPE, "application/json;charset=UTF-8") .header("Sign", sign) //Signature with encryption .header("Timestamp", datetime) //Current system time stamp (second) .header("Api-Key", apiKey); //API KEY(Home-Developer options) final String params = JSONUtil.createObj() .set("appId", appId) .set("fromEmailAddress", fromEmailAddress) .set("toAddress", toAddress) .set("subject", subject) .set("templateID", templateID) .set("templateData", templateData) .set("adFlag", adFlag) .set("language", language) .set("checkEmailAddress", checkEmailAddress) .set("isUnsubscribe", isUnsubscribe) .toString(); HttpResponse response = request.body(params).execute(); if (response.isOk()) { String result = response.body(); System.out.println(result); } } }