Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# sendgrid向Azure中的多个收件人发送电子邮件功能失败_C#_Azure_Azure Functions_Sendgrid_Sendgrid Api V3 - Fatal编程技术网

C# sendgrid向Azure中的多个收件人发送电子邮件功能失败

C# sendgrid向Azure中的多个收件人发送电子邮件功能失败,c#,azure,azure-functions,sendgrid,sendgrid-api-v3,C#,Azure,Azure Functions,Sendgrid,Sendgrid Api V3,(有关此问题的完整版本,请参阅 ) 向单个收件人发送成功。但在Azure函数中找不到发送给多个收件人或抄送/密件抄送的方法 尝试了多种格式,包括 { "to": [{ "email": ["john.doe@example.com", "sendgridtesting@gmail.com" ] }] } 这似乎是azure功能的限制。但还不确定哪里出了问题。请参阅下面的“绑定” 我使用HTTP触发器完成了我的示例,但基于此,您将能够使用服务总线触发器使其工作 my function.json:

(有关此问题的完整版本,请参阅 )

向单个收件人发送成功。但在Azure函数中找不到发送给多个收件人或抄送/密件抄送的方法

尝试了多种格式,包括

{ "to": [{ "email": ["john.doe@example.com", "sendgridtesting@gmail.com" ] }] }
这似乎是azure功能的限制。但还不确定哪里出了问题。请参阅下面的“绑定”


我使用HTTP触发器完成了我的示例,但基于此,您将能够使用服务总线触发器使其工作

my function.json:

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "sendGrid",
      "name": "mails",
      "apiKey": "MySendGridKey",
      "direction": "out",
      "from":"samples@functions.com"
    }
  ],
  "disabled": false
}
My run.csx:

#r "SendGrid"

using System;
using System.Net;
using SendGrid.Helpers.Mail;

public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ICollector<Mail> mails)
{
    log.Info("C# HTTP trigger function processed a request.");

    Mail message = new Mail()
    {
        Subject = $"Hello world from the SendGrid C#!"
    };

    var personalization = new Personalization();
    personalization.AddTo(new Email("foo@bar.com"));  
    personalization.AddTo(new Email("foo2@bar.com")); 
    // you can add some more recipients here 

    Content content = new Content
    {
        Type = "text/plain",
        Value = $"Hello world!"
    };

    message.AddContent(content);  
    message.AddPersonalization(personalization); 
    mails.Add(message);

    return null;
}
#r“SendGrid”
使用制度;
Net系统;
使用SendGrid.Helpers.Mail;
公共静态HttpResponseMessage运行(HttpRequestMessage请求、TraceWriter日志、ICollector邮件)
{
Info(“C#HTTP触发器函数处理了一个请求。”);
邮件消息=新邮件()
{
主题=$“来自SendGrid的Hello world C#!”
};
var personalization=新的personalization();
personalization.AddTo(新电子邮件(“foo@bar.com"));  
personalization.AddTo(新电子邮件(“foo2@bar.com")); 
//您可以在此处添加更多收件人
内容=新内容
{
Type=“text/plain”,
值=$“你好,世界!”
};
message.AddContent(content);
message.AddPersonalization(个性化);
邮件。添加(消息);
返回null;
}
我使用此源代码构建我的示例:
多亏了Tamás Huj,该功能现在可以完成这项工作。因此,我发布了详细的解决方案,供其他人参考

{
"bindings": [

{

"name": "telemetryEvent",

"type": "serviceBusTrigger", 

"direction": "in",

"queueName": "threshold-email-queue",

"connection": "RootManageSharedAccessKey_SERVICEBUS",

"accessRights": "Manage"

},

{

"type": "sendGrid",

"name": "$return",

"apiKey": "SendGridKey",

"direction": "out",

"from": "ABC@sample.com"

}

],
"disabled": false

}
然后将run.csx编写为:

#r "SendGrid"
#r "Newtonsoft.Json"

using System;
using SendGrid.Helpers.Mail;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

public static Mail Run(string telemetryEvent, TraceWriter log)
{
    var telemetry = JsonConvert.DeserializeObject<Telemetry>(telemetryEvent);

Mail message = new Mail()
{
    Subject = "Write your own subject"
};

var personalization = new Personalization();
personalization.AddBcc(new Email("sample1@test.com"));  
personalization.AddTo(new Email("sample2@test.com")); 
//add more Bcc,cc and to here as needed

Content content = new Content
{
    Type = "text/plain",
    Value = $"The temperature value is{temperature.Temperature}."
};

message.AddContent(content); 
message.AddPersonalization(personalization); 

    return message;
}


public class Telemetry 
{
    public float Temperature { get; set; }
}
#r“SendGrid”
#r“Newtonsoft.Json”
使用制度;
使用SendGrid.Helpers.Mail;
使用System.Threading.Tasks;
使用Microsoft.Azure.WebJobs.Host;
使用Newtonsoft.Json;
公共静态邮件运行(字符串遥测事件、TraceWriter日志)
{
var telemetry=JsonConvert.DeserializeObject(遥测事件);
邮件消息=新邮件()
{
主题=“写你自己的主题”
};
var personalization=新的personalization();
personalization.AddBcc(新电子邮件(“sample1@test.com"));  
personalization.AddTo(新电子邮件(“sample2@test.com")); 
//根据需要在此处添加更多密件抄送、抄送和
内容=新内容
{
Type=“text/plain”,
Value=$“温度值为{temperature.temperature}。”
};
message.AddContent(content);
message.AddPersonalization(个性化);
返回消息;
}
公共级遥测
{
公共浮子温度{get;set;}
}
#r "SendGrid"
#r "Newtonsoft.Json"

using System;
using SendGrid.Helpers.Mail;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

public static Mail Run(string telemetryEvent, TraceWriter log)
{
    var telemetry = JsonConvert.DeserializeObject<Telemetry>(telemetryEvent);

Mail message = new Mail()
{
    Subject = "Write your own subject"
};

var personalization = new Personalization();
personalization.AddBcc(new Email("sample1@test.com"));  
personalization.AddTo(new Email("sample2@test.com")); 
//add more Bcc,cc and to here as needed

Content content = new Content
{
    Type = "text/plain",
    Value = $"The temperature value is{temperature.Temperature}."
};

message.AddContent(content); 
message.AddPersonalization(personalization); 

    return message;
}


public class Telemetry 
{
    public float Temperature { get; set; }
}