New file |
| | |
| | | package com.moral.util; |
| | | |
| | | import com.aliyuncs.DefaultAcsClient; |
| | | import com.aliyuncs.IAcsClient; |
| | | import com.aliyuncs.dm.model.v20151123.SingleSendMailRequest; |
| | | import com.aliyuncs.dm.model.v20151123.SingleSendMailResponse; |
| | | import com.aliyuncs.exceptions.ClientException; |
| | | import com.aliyuncs.exceptions.ServerException; |
| | | import com.aliyuncs.profile.DefaultProfile; |
| | | import com.aliyuncs.profile.IClientProfile; |
| | | |
| | | public class AlarmUtils_2 { |
| | | |
| | | /** |
| | | * |
| | | * @return |
| | | */ |
| | | public static SingleSendMailResponse sendMail(String mailAddress, String mailSubject, String mailBody){ |
| | | // 如果是除杭州region外的其它region(如新加坡、澳洲Region),需要将下面的"cn-hangzhou"替换为"ap-southeast-1"、或"ap-southeast-2"。 |
| | | IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIV1JE1gsLMjpn", "5NpYfVwrvBL9BtEoDymFTQUGPyNBa2"); |
| | | // 如果是除杭州region外的其它region(如新加坡region), 需要做如下处理 |
| | | //try { |
| | | //DefaultProfile.addEndpoint("dm.ap-southeast-1.aliyuncs.com", "ap-southeast-1", "Dm", "dm.ap-southeast-1.aliyuncs.com"); |
| | | //} catch (ClientException e) { |
| | | //e.printStackTrace(); |
| | | //} |
| | | IAcsClient client = new DefaultAcsClient(profile); |
| | | SingleSendMailRequest request = new SingleSendMailRequest(); |
| | | try { |
| | | //request.setVersion("2017-06-22");// 如果是除杭州region外的其它region(如新加坡region),必须指定为2017-06-22 |
| | | request.setAccountName("postmaster@email.7drlb.com"); |
| | | request.setFromAlias("七星瓢虫环境科技"); |
| | | request.setAddressType(1); |
| | | request.setTagName("testemail"); |
| | | request.setReplyToAddress(true); |
| | | request.setToAddress(mailAddress); |
| | | request.setSubject(mailSubject); |
| | | request.setHtmlBody(mailBody); |
| | | SingleSendMailResponse httpResponse = client.getAcsResponse(request); |
| | | //System.out.println(httpResponse.getRequestId()); |
| | | //System.out.println("=========================================="); |
| | | } catch (ServerException e) { |
| | | e.printStackTrace(); |
| | | } catch (ClientException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |