admin
2024-09-05 ab35ac8b769b2d9816dffb33a64f2c6f7bd5dd6e
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.yeshi.buwan.util;
 
/**
 * @author hxh
 * @title: TencentCloudEmailUtil
 * @description: 腾讯云短信发送
 * @date 2024/7/17 13:21
 */
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import  com.tencentcloudapi.ses.v20201002.SesClient;
import com.tencentcloudapi.ses.v20201002.models.SendEmailRequest;
import com.tencentcloudapi.ses.v20201002.models.SendEmailResponse;
import com.tencentcloudapi.ses.v20201002.models.Template;
import net.sf.json.JSONObject;
 
import java.util.HashMap;
import java.util.Map;
 
public class TencentCloudEmailUtil {
 
   private   static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
    private   static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo";
 
    public static void sendEmail() throws TencentCloudSDKException {
        EmailEntity emailEntity=new EmailEntity();
        emailEntity.setSecretId(secretId);
        emailEntity.setSecretKey(secretKey);
        emailEntity.setFromEmailAddress("ysdq@email.yeshitv.com");
        Map<String,String> data=new HashMap<>();
        data.put("code","123123");
        emailEntity.setTemplateData(data);
        emailEntity.setTemplateId(28962L);
        emailEntity.setTitle("影视大全验证码");
        emailEntity.setToEmailAddress("hexiaohui@banliapp.com");
        sendEmail(emailEntity);
    }
 
    public static void sendEmail(EmailEntity entity) throws TencentCloudSDKException {
        SesClient client =   new SesClient(new Credential(entity.getSecretId(),entity.getSecretKey()),"ap-guangzhou");
        SendEmailRequest request = new SendEmailRequest();
        request.setFromEmailAddress(entity.getFromEmailAddress());
        request.setSubject(entity.getTitle());
        request.setDestination(new String[]{entity.getToEmailAddress()});
        Template template=  new Template();
        template.setTemplateID(entity.getTemplateId());
        template.setTemplateData(JSONObject.fromObject(entity.getTemplateData()).toString());
        request.setTemplate(template);
        SendEmailResponse response = client.SendEmail(request);
    }
 
    public static void main(String[] args) throws TencentCloudSDKException {
        sendEmail();
 
    }
 
    public static class EmailEntity{
      private String  secretId;
      private String  secretKey;
      private String fromEmailAddress;
      private String title;
      private Long templateId;
      private Map<String,String> templateData;
      private String toEmailAddress;
 
        public String getSecretId() {
            return secretId;
        }
 
        public void setSecretId(String secretId) {
            this.secretId = secretId;
        }
 
        public String getSecretKey() {
            return secretKey;
        }
 
        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }
 
        public String getFromEmailAddress() {
            return fromEmailAddress;
        }
 
        public void setFromEmailAddress(String fromEmailAddress) {
            this.fromEmailAddress = fromEmailAddress;
        }
 
        public String getTitle() {
            return title;
        }
 
        public void setTitle(String title) {
            this.title = title;
        }
 
        public Long getTemplateId() {
            return templateId;
        }
 
        public void setTemplateId(Long templateId) {
            this.templateId = templateId;
        }
 
        public Map<String, String> getTemplateData() {
            return templateData;
        }
 
        public void setTemplateData(Map<String, String> templateData) {
            this.templateData = templateData;
        }
 
        public String getToEmailAddress() {
            return toEmailAddress;
        }
 
        public void setToEmailAddress(String toEmailAddress) {
            this.toEmailAddress = toEmailAddress;
        }
    }
 
}