All Products
Search
Document Center

Csharp SDK tutorial(Australia and Singapore Region)

Last Updated: Apr 16, 2019

Create an AccessKey

  1. Log on to the AccessKey console.
  2. Click Create AccessKey at the upper-right corner of the page.
  3. 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:

  1. .NET Framework 4.6.1 or later
  2. .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

  1. Install-Package aliyun-net-sdk-core
  2. 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):

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.Dm.Model.V20170622;
  6. namespace ConsoleApp
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. //Region-Id: ap-southeast-1 for Singapore Region and ap-southeast-1 for Australlia Region
  13. string regionId = "ap-southeast-1";
  14. //Region-Host: dm.ap-southeast-1.aliyuncs.com for Singapore Region and dm.ap-southeast-2.aliyuncs.com for Australlia Region
  15. string regionHost = "dm.ap-southeast-1.aliyuncs.com";
  16. IClientProfile profile = DefaultProfile.GetProfile(regionId, "<your accessKey>", "<your accessSecret>");
  17. IAcsClient client = new DefaultAcsClient(profile);
  18. DefaultProfile.AddEndpoint(regionHost, regionId, "Dm", regionHost);
  19. SingleSendMailRequest request = new SingleSendMailRequest();
  20. try {
  21. request.AccountName = "Sender address created in the console";
  22. request.FromAlias = "Sender nickname";
  23. request.AddressType = 1;
  24. request.TagName = "Tag created in the console";
  25. request.ReplyToAddress = true;
  26. request.ToAddress = "Destination address";
  27. request.Subject = "Subject";
  28. request.HtmlBody = "Body";
  29. SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
  30. System.Console.WriteLine(httpResponse.RequestId);
  31. } catch (ServerException e) {
  32. System.Console.WriteLine(e.ToString());
  33. }
  34. catch (ClientException e) {
  35. System.Console.WriteLine(e.ToString());
  36. }
  37. }
  38. }
  39. }