.NET使用Nuget阿里官方aliyun-net-sdk-core调用阿里云Direct Mail
由于版本问题,阿里云Direct Mail提供的相关dll只能与一同提供的aliyun-net-sdk-core配合使用,无法兼容Nuget上阿里官方上传的aliyun-net-sdk-core。如果在一个类库内封装多个阿里云相关功能,就会出现需要引用多个aliyun-net-sdk-core的情况,但是显然是不能如此引用的。
参考之前调用阿里云SMS的做法,只要将相关功能需要的实体添加到项目中,然后调用Nuget上的aliyun-net-sdk-core即可。
SingleSendMailRequest:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class SingleSendMailRequest : RpcAcsRequest<SingleSendMailResponse> 2 { 3 public SingleSendMailRequest() : base("Dm", "2015-11-23", "SingleSendMail") 4 { 5 } 6 7 private long? ownerId; 8 9 private string resourceOwnerAccount; 10 11 private long? resourceOwnerId; 12 13 private string accountName; 14 15 private int? addressType; 16 17 private string tagName; 18 19 private bool? replyToAddress; 20 21 private string toAddress; 22 23 private string subject; 24 25 private string htmlBody; 26 27 private string textBody; 28 29 private string fromAlias; 30 31 private string replyAddress; 32 33 private string replyAddressAlias; 34 35 private string clickTrace; 36 37 public string ClickTrace 38 { 39 get 40 { 41 return clickTrace; 42 } 43 set 44 { 45 clickTrace = value; 46 DictionaryUtil.Add(QueryParameters, "ClickTrace", value); 47 } 48 } 49 50 public long? OwnerId 51 { 52 get 53 { 54 return ownerId; 55 } 56 set 57 { 58 ownerId = value; 59 DictionaryUtil.Add(QueryParameters, "OwnerId", value.ToString()); 60 } 61 } 62 63 public string ResourceOwnerAccount 64 { 65 get 66 { 67 return resourceOwnerAccount; 68 } 69 set 70 { 71 resourceOwnerAccount = value; 72 DictionaryUtil.Add(QueryParameters, "ResourceOwnerAccount", value); 73 } 74 } 75 76 public long? ResourceOwnerId 77 { 78 get 79 { 80 return resourceOwnerId; 81 } 82 set 83 { 84 resourceOwnerId = value; 85 DictionaryUtil.Add(QueryParameters, "ResourceOwnerId", value.ToString()); 86 } 87 } 88 89 public string AccountName 90 { 91 get 92 { 93 return accountName; 94 } 95 set 96 { 97 accountName = value; 98 DictionaryUtil.Add(QueryParameters, "AccountName", value); 99 } 100 } 101 102 public int? AddressType 103 { 104 get 105 { 106 return addressType; 107 } 108 set 109 { 110 addressType = value; 111 DictionaryUtil.Add(QueryParameters, "AddressType", value.ToString()); 112 } 113 } 114 115 public string TagName 116 { 117 get 118 { 119 return tagName; 120 } 121 set 122 { 123 tagName = value; 124 DictionaryUtil.Add(QueryParameters, "TagName", value); 125 } 126 } 127 128 public bool? ReplyToAddress 129 { 130 get 131 { 132 return replyToAddress; 133 } 134 set 135 { 136 replyToAddress = value; 137 DictionaryUtil.Add(QueryParameters, "ReplyToAddress", value.ToString()); 138 } 139 } 140 141 public string ToAddress 142 { 143 get 144 { 145 return toAddress; 146 } 147 set 148 { 149 toAddress = value; 150 DictionaryUtil.Add(QueryParameters, "ToAddress", value); 151 } 152 } 153 154 public string Subject 155 { 156 get 157 { 158 return subject; 159 } 160 set 161 { 162 subject = value; 163 DictionaryUtil.Add(QueryParameters, "Subject", value); 164 } 165 } 166 167 public string HtmlBody 168 { 169 get 170 { 171 return htmlBody; 172 } 173 set 174 { 175 htmlBody = value; 176 DictionaryUtil.Add(QueryParameters, "HtmlBody", value); 177 } 178 } 179 180 public string TextBody 181 { 182 get 183 { 184 return textBody; 185 } 186 set 187 { 188 textBody = value; 189 DictionaryUtil.Add(QueryParameters, "TextBody", value); 190 } 191 } 192 193 public string FromAlias 194 { 195 get 196 { 197 return fromAlias; 198 } 199 set 200 { 201 fromAlias = value; 202 DictionaryUtil.Add(QueryParameters, "FromAlias", value); 203 } 204 } 205 206 public string ReplyAddress 207 { 208 get 209 { 210 return replyAddress; 211 } 212 set 213 { 214 replyAddress = value; 215 DictionaryUtil.Add(QueryParameters, "ReplyAddress", value); 216 } 217 } 218 219 public string ReplyAddressAlias 220 { 221 get 222 { 223 return replyAddressAlias; 224 } 225 set 226 { 227 replyAddressAlias = value; 228 DictionaryUtil.Add(QueryParameters, "ReplyAddressAlias", value); 229 } 230 } 231 232 public override SingleSendMailResponse GetResponse(UnmarshallerContext unmarshallerContext) 233 { 234 SingleSendMailResponse singleSendMailResponse = new SingleSendMailResponse 235 { 236 HttpResponse = unmarshallerContext.HttpResponse, 237 RequestId = unmarshallerContext.StringValue("SingleSendMail.RequestId"), 238 EnvId = unmarshallerContext.StringValue("SingleSendMail.EnvId"), 239 }; 240 241 return singleSendMailResponse; 242 } 243 }
SingleSendMailResponse:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class SingleSendMailResponse : AcsResponse 2 { 3 public string EnvId { get; set; } 4 }
BatchSendMailRequest:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class BatchSendMailRequest : RpcAcsRequest<BatchSendMailResponse> 2 { 3 public BatchSendMailRequest() : base("Dm", "2015-11-23", "BatchSendMail") 4 { 5 } 6 7 private long? ownerId; 8 9 private string resourceOwnerAccount; 10 11 private long? resourceOwnerId; 12 13 private string templateName; 14 15 private string accountName; 16 17 private string receiversName; 18 19 private int? addressType; 20 21 private string tagName; 22 23 private string replyAddress; 24 25 private string replyAddressAlias; 26 27 private string clickTrace; 28 29 public long? OwnerId 30 { 31 get 32 { 33 return ownerId; 34 } 35 set 36 { 37 ownerId = value; 38 DictionaryUtil.Add(QueryParameters, "OwnerId", value.ToString()); 39 } 40 } 41 42 public string ResourceOwnerAccount 43 { 44 get 45 { 46 return resourceOwnerAccount; 47 } 48 set 49 { 50 resourceOwnerAccount = value; 51 DictionaryUtil.Add(QueryParameters, "ResourceOwnerAccount", value); 52 } 53 } 54 55 public long? ResourceOwnerId 56 { 57 get 58 { 59 return resourceOwnerId; 60 } 61 set 62 { 63 resourceOwnerId = value; 64 DictionaryUtil.Add(QueryParameters, "ResourceOwnerId", value.ToString()); 65 } 66 } 67 68 public string TemplateName 69 { 70 get 71 { 72 return templateName; 73 } 74 set 75 { 76 templateName = value; 77 DictionaryUtil.Add(QueryParameters, "TemplateName", value); 78 } 79 } 80 81 public string AccountName 82 { 83 get 84 { 85 return accountName; 86 } 87 set 88 { 89 accountName = value; 90 DictionaryUtil.Add(QueryParameters, "AccountName", value); 91 } 92 } 93 94 public string ReceiversName 95 { 96 get 97 { 98 return receiversName; 99 } 100 set 101 { 102 receiversName = value; 103 DictionaryUtil.Add(QueryParameters, "ReceiversName", value); 104 } 105 } 106 107 public int? AddressType 108 { 109 get 110 { 111 return addressType; 112 } 113 set 114 { 115 addressType = value; 116 DictionaryUtil.Add(QueryParameters, "AddressType", value.ToString()); 117 } 118 } 119 120 public string TagName 121 { 122 get 123 { 124 return tagName; 125 } 126 set 127 { 128 tagName = value; 129 DictionaryUtil.Add(QueryParameters, "TagName", value); 130 } 131 } 132 133 public string ReplyAddress 134 { 135 get 136 { 137 return replyAddress; 138 } 139 set 140 { 141 replyAddress = value; 142 DictionaryUtil.Add(QueryParameters, "ReplyAddress", value); 143 } 144 } 145 146 public string ReplyAddressAlias 147 { 148 get 149 { 150 return replyAddressAlias; 151 } 152 set 153 { 154 replyAddressAlias = value; 155 DictionaryUtil.Add(QueryParameters, "ReplyAddressAlias", value); 156 } 157 } 158 159 public string ClickTrace 160 { 161 get 162 { 163 return clickTrace; 164 } 165 set 166 { 167 clickTrace = value; 168 DictionaryUtil.Add(QueryParameters, "ClickTrace", value); 169 } 170 } 171 172 public override BatchSendMailResponse GetResponse(UnmarshallerContext unmarshallerContext) 173 { 174 BatchSendMailResponse batchSendMailResponse = new BatchSendMailResponse 175 { 176 HttpResponse = unmarshallerContext.HttpResponse, 177 RequestId = unmarshallerContext.StringValue("BatchSendMail.RequestId"), 178 EnvId = unmarshallerContext.StringValue("BatchSendMail.EnvId"), 179 }; 180 181 return batchSendMailResponse; 182 } 183 }
BatchSendMailResponse:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class BatchSendMailResponse : AcsResponse 2 { 3 public string EnvId { get; set; } 4 }