-1

我已将 Send Grid API Key 添加到应用程序设置中,如下所示:

在此处输入图像描述

我有一个带有资源元素的 ARM 模板,其中包括以下内容:

"resources": [               
    {
       "apiVersion": "2016-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('apiApp').name)]"
        ],
        "properties": {
           "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(variables('dataResourceGroup').name, 'Microsoft.Insights/components', variables('dataAppInsights').name), '2014-04-01').InstrumentationKey]",
           "apiClientId": "[parameters('apiAppId')]",
           "prereqsKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-prereqs-', parameters('environmentAbbreviation'))]",
           "dataKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-data-', parameters('environmentAbbreviation'))]"
         }
     }
]

如何将 SENDGRID_APIKEY 添加到 ARM 模板并在下面显示的程序中使用它?

    private static void Main()
    {
        Execute().Wait();
    }
    static async Task Execute()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("abc.com", "ABC");
        var subject = "Testing SendGrid";
        var to = new EmailAddress("xyz.com", "XYZ"); 
        var plainTextContent = "This is a test";
        var htmlContent = "test";
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = await client.SendEmailAsync(msg);
    }
4

1 回答 1

1

我不明白这个问题,只需将其添加为另一个键\值对?

"resources": [               
    {
       "apiVersion": "2016-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('apiApp').name)]"
        ],
        "properties": {
           "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(variables('dataResourceGroup').name, 'Microsoft.Insights/components', variables('dataAppInsights').name), '2014-04-01').InstrumentationKey]",
           "apiClientId": "[parameters('apiAppId')]",
           "prereqsKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-prereqs-', parameters('environmentAbbreviation'))]",
           "dataKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-data-', parameters('environmentAbbreviation'))]",
           "SENDGRIP_APIKEY": "somevalue"
         }
     }
]

如果您想动态传递它,请添加另一个参数并像其他任何操作一样引用该参数[parameters('sendgrid')]

于 2018-11-02T05:42:47.670 回答