All Products
Search
Document Center

Direct Mail:CSharp SDK Tutorial

Last Updated:Nov 23, 2022

This topic describes how to install and use the C# SDK.

Create an Access Key

(Note: You can also use the Access Key created by Alibaba Cloud RAM Service.)

  1. Log on to the Access Key Management console.

  2. Click Create Access Key in the upper-right corner of the page. The Create Access Key dialog box appears.

  3. Read the API usage specifications and click Agree and Create.

Install the C# SDK

Development Environment

The C# SDK Direct Mail by Alibaba Cloud supports. Net Framework 2.0 or later.

Install the SDK

Install through dotnet

1. Add dependency package

You can obtain the new version number on the OpenAPI page and "SDK dependency information".

dotnet add package AlibabaCloud.SDK.Dm20151123 --version 1.0.x

2. Jump to openAPI for debugging, select the development language, enter parameters, and download the automatically generated code (the parameter value will be included).

The debugging page does not need to fill in the Key value. When using in other environments, please fill in the corresponding "accessKeyId" and "accessKeySecret" values in the code.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

image

The installation method of the old SDK.

Download Tablestore SDK for Node.js

Direct download: https://aliyundm.oss-cn-hangzhou.aliyuncs.com/example/aliyun-net-sdk-dmV3.1.0.zip.

Install the SDK

  1. You can find the aliyun-net-sdk-core.dll and aliyun-net-sdk-dm.dll files in the decompressed file.

  2. Right-click the project in Visual Studio, and then choose Add Reference > Browse. If you are using MonoDevelop, import the. dll file as required. Select the. dll file and click OK.

    You can use Alibaba Cloud Direct Mail C# SDK in your project.

Example of sending email

Example of how to call a single sender API (see SingleSendMail ). If you need to know the details of GetProfile and DefaultAcsClient in the sample code, you can view the source code:

    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Exceptions;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Dm.Model.V20151123;

    namespace ConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create a client used for initiating a request
                IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<your accessKey", "<your accessSecret>");
                IAcsClient client = new DefaultAcsClient(profile);
                SingleSendMailRequest request = new SingleSendMailRequest();
                try {
                    //Version must set to "2017-06-22" when the regionId is not "cn-hangzhou"
                    //request.Version = "2017-06-22";
                    request.AccountName = "The sender address created in the console";
                    request.FromAlias = "Sender's nickname";
                    request.AddressType = 1;
                    request.TagName = "The tag created in the console";
                    request.ReplyToAddress = true;
                    request.ToAddress = "Destination address";
                    request.Subject = "Email subject" ;
                    request.HtmlBody = "Email body" ;
                    SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
                } catch (ServerException e) {
                    System.Console.WriteLine(e.ToString());
                }
                catch (ClientException e) {
                    System.Console.WriteLine(e.ToString());
                }
            }
        }
    }