zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);
        }
    }
 
}