3步对接阿里云发送邮件

今天教你3步对接阿里云的发送邮件

  1. 使用你的包管理工具安装包AlibabaCloud.SDK.Dm2015112

  2. 创建Client

1
2
3
4
5
6
7
8
9
10
11
12
13
public static AlibabaCloud.SDK.Dm20151123.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 您的AccessKey ID
AccessKeyId = accessKeyId,
// 您的AccessKey Secret
AccessKeySecret = accessKeySecret,
};
// 访问的域名, 不同的数据中心,你的域名不同
config.Endpoint = "dm.ap-southeast-1.aliyuncs.com";
return new AlibabaCloud.SDK.Dm20151123.Client(config);
}
  1. 发送邮件 (或者调用其他接口)
    1
    2
    AlibabaCloud.SDK.Dm20151123.Models.SingleSendMailRequest singleSendMailRequest = new AlibabaCloud.SDK.Dm20151123.Models.SingleSendMailRequest();
    client.SingleSendMail(singleSendMailRequest);

注意: 对于澳洲和新加坡区域的用户,需要使用另外一个包 - https://www.alibabacloud.com/help/zh/doc-detail/113955.htm?spm=a2c63.p38356.b99.61.664a6f18AGrooo
同时, SDK要选择2017-06-22的, 虽然这个包被官方标注为不推荐 - https://next.api.aliyun.com/api/Dm/2017-06-22/SingleSendMail?params={}&sdkStyle=old