官术网_书友最值得收藏!

How to do it...

  1. Navigate to the Integrate tab of the RegisterUser function and click on the New Output button to add a new output binding.
  2. Choose the SendGrid binding and click on the Select button to add the binding.
  3. Provide the following parameters in the SendGrid output (message) binding:
    • Message parameter name: Leave the default value, which is message. We will be using this parameter in the Run method in a moment.
    • SendGrid API Key: Provide the App settings key that you have created in Application settings.
    • To address: Provide the email address of the administrator.
    • From address: Provide the email address from where you would like to send the email. In general, it would be something like donotreply@example.com.
    • Message subject: Provide the subject that you would like to have in the email subject.
    • Message Text: Provide the email body text that you would like to have in the email body.
  4. This is how the SendGrid output (message) binding should look like after providing all the fields:
  1. Once you review the values, click on Save to save the changes.
  2. Navigate to the Run method and make the following changes:
    • Add a new reference for SendGrid and also the namespace SendGrid.Helpers.Mail.
    • Add a new out parameter message of type Mail.
    • Create an object of type Mail. We will understand how to use this object in the next recipe.
  3. The following is the complete code of the Run method:
        #r "Microsoft.WindowsAzure.Storage"
#r "SendGrid"

using System.Net;
using SendGrid.Helpers.Mail;
using Microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;
public static void Run(HttpRequestMessage req,
TraceWriter log,
CloudTable
objUserProfileTable,
out string
objUserProfileQueueItem,
out Mail message
)
{
var inputs =
req.Content.ReadAsStringAsync().Result;
dynamic inputJson =
JsonConvert.DeserializeObject<dynamic>
(inputs);

string firstname= inputJson.firstname;
string lastname=inputJson.lastname;
string profilePicUrl =
inputJson.ProfilePicUrl;

objUserProfileQueueItem = profilePicUrl;

UserProfile objUserProfile = new
UserProfile(firstname, lastname);
TableOperation objTblOperationInsert =
TableOperation.Insert(objUserProfile);
objUserProfileTable.Execute
(objTblOperationInsert);

message = new Mail();

}
public class UserProfile : TableEntity
{
public UserProfile(string lastName, string
firstname,string profilePicUrl)
{
this.PartitionKey = "p1";
this.RowKey = Guid.NewGuid().ToString();;
this.FirstName = firstName;
this.LastName = lastName;
this.ProfilePicUrl = profilePicUrl;
}
public UserProfile() { }
public string FirstName { get; set; }
public string LastName { get; set; }
public string ProfilePicUrl {get; set;}
}
  1. Now, let's test the functionality of sending the email by navigating to the RegisterUser function and submitting a request with the some test values, as follows:
        {
"firstname": "Bill",
"lastname": "Gates",
"ProfilePicUrl":"https://upload.wikimedia.org/
wikipedia/commons/thumb/1/19/
Bill_Gates_June_2015.jpg/220px-
Bill_Gates_June_2015.jpg"
}
主站蜘蛛池模板: 色达县| 临泽县| 苏尼特左旗| 长武县| 建湖县| 华容县| 和龙市| 蕲春县| 黎川县| 含山县| 博客| 阆中市| 德钦县| 江永县| 内丘县| 泸水县| 弋阳县| 威宁| 波密县| 桑植县| 景谷| 平凉市| 武清区| 巫溪县| 泰宁县| 乌苏市| 德昌县| 顺平县| 江都市| 江永县| 秀山| 阳城县| 鄄城县| 彝良县| 北京市| 东丽区| 彰化县| 泊头市| 台州市| 永定县| 龙海市|