Reputation: 393
I have an eventhubtriggered azure function the code is below
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 = "[email protected]", from = "[email protected]", subject = "Azure Functions email with SendGrid", text = "Sent from Azure Functions") OutputBinding<String> message,
final ExecutionContext context) {
final String toAddress = "[email protected]";
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);
}
}
As you can see I have used @SendGridOutput annotation and inside that I have from and to email addresses. The function.json generated is as shown below
{
"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" : "[email protected]",
"to" : "[email protected]",
"text" : "Sent from Azure Functions"
} ]
}
So there is only one receiver for this email. Is there any way to send the same email to multiple users?
Upvotes: 0
Views: 267
Reputation: 222722
You need to manage that using the Personalization
var personalization = new Personalization();
personalization.AddBcc(new Email("[email protected]"));
personalization.AddTo(new Email("[email protected]"));
Upvotes: 1