我可以使用SendGrid向多个用户发送电子邮件吗?



我有一个eventhubtriggered azure函数,代码如下

public class Function {
@FunctionName("ehprocessor")
public void eventHubProcessor(
@EventHubTrigger(name = "msg", eventHubName = "", connection = "eventhubConnString", dataType = "string", cardinality = Cardinality.ONE) String eventHubMessage,
@SendGridOutput(name = "message", dataType = "String", apiKey = "sendGridAPIKey", to = "jithinvariyarmv@gmail.com", from = "jithin@vinnovatelabz.com", subject = "Azure Functions email with SendGrid", text = "Sent from Azure Functions") OutputBinding<String> message,
final ExecutionContext context) {
final String toAddress = "jithinvariyarmv@gmail.com";
final String value = "Sent from Azure Functions-->" + eventHubMessage;
StringBuilder builder = new StringBuilder().append("{")
.append(""personalizations": [{ "to": [{ "email": "%s"}]}],")
.append(""content": [{"type": "text/plain", "value": "%s"}]").append("}");
final String body = String.format(builder.toString(), toAddress, value);
message.setValue(body);
}
}

正如你所看到的,我已经使用了@SendGridOutput注释,里面我有来自和到电子邮件地址。这个函数。生成的Json如下所示

{
"scriptFile" : "../eventfunction-0.0.1-SNAPSHOT.jar",
"entryPoint" : "dk.scanomat.coffeecloud.eventfunction.Function.eventHubProcessor",
"bindings" : [ {
"type" : "eventHubTrigger",
"direction" : "in",
"name" : "msg",
"dataType" : "string",
"connection" : "eventhubConnString",
"eventHubName" : "",
"cardinality" : "ONE"
}, {
"type" : "sendGrid",
"direction" : "out",
"name" : "message",
"apiKey" : "sendGridAPIKey",
"subject" : "Azure Functions email with SendGrid",
"dataType" : "String",
"from" : "jithin@vinnovatelabz.com",
"to" : "jithinvariyarmv@gmail.com",
"text" : "Sent from Azure Functions"
} ]
}

所以这封邮件只有一个收件人。是否有办法向多个用户发送相同的电子邮件?

您需要使用Personalization

来管理它
var personalization = new Personalization();
personalization.AddBcc(new Email("mark@test.com"));  
personalization.AddTo(new Email("bob@test.com")); 

最新更新