Create an AccessKey
- Log on to the AccessKey console.
- Click Create AccessKey at the upper-right corner of the page.
- Read API Terms of Use, and click Agree and Create.
Note: You can use the AccessKey of ram users granted with system policy “AliyunDirectMailFullAccess”. Ram users can be created with Alibaba Cloud Resource Access Management service.
Install the C# SDK
Requirements
The Alibaba Cloud SDK for .NET requires:
.NET Framework 4.6.1 or later
.NET Standard 2.0 or later
Install the SDK
You must install the SDK core Nuget Package for any SDK you use.
Use Package Manager
Install-Package aliyun-net-sdk-core
Install-Package aliyun-net-sdk-dm-overseas -Version 4.7.2
You can also use the Visual Studio to install for .NET Framework Application referring to https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio with searching our SDK name “aliyun-net-sdk-dm-overseas” in the package brower.
Email sending example
Take calling the API to send a single email as an example (for how to call the interface, see SingleSendMail):
using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Dm.Model.V20170622;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
//Region-Id: ap-southeast-1 for Singapore Region and ap-southeast-1 for Australlia Region
string regionId = "ap-southeast-1";
//Region-Host: dm.ap-southeast-1.aliyuncs.com for Singapore Region and dm.ap-southeast-2.aliyuncs.com for Australlia Region
string regionHost = "dm.ap-southeast-1.aliyuncs.com";
IClientProfile profile = DefaultProfile.GetProfile(regionId, "<your accessKey>", "<your accessSecret>");
IAcsClient client = new DefaultAcsClient(profile);
DefaultProfile.AddEndpoint(regionHost, regionId, "Dm", regionHost);
SingleSendMailRequest request = new SingleSendMailRequest();
try {
request.AccountName = "Sender address created in the console";
request.FromAlias = "Sender nickname";
request.AddressType = 1;
request.TagName = "Tag created in the console";
request.ReplyToAddress = true;
request.ToAddress = "Destination address";
request.Subject = "Subject";
request.HtmlBody = "Body";
SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
System.Console.WriteLine(httpResponse.RequestId);
} catch (ServerException e) {
System.Console.WriteLine(e.ToString());
}
catch (ClientException e) {
System.Console.WriteLine(e.ToString());
}
}
}
}