SendGrid和Arm模板

时间:2018-11-01 21:56:43

标签: azure sendgrid arm-template sendgrid-templates

我已将“发送网格API密钥”添加到“应用程序设置”中,如下所示:

enter image description here

我有一个带有资源元素的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);
    }

1 个答案:

答案 0 :(得分:0)

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

"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')]一样引用该参数