代码之家  ›  专栏  ›  技术社区  ›  user989988

sendgrid和arm模板

  •  -1
  • user989988  · 技术社区  · 6 年前

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

    enter image description here

    我有一个带有resources元素的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 回复  |  直到 6 年前
        1
  •  0
  •   4c74356b41    6 年前

    我不理解这个问题,只是把它作为另一个键\值对添加?

    "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')]