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

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"
}
主站蜘蛛池模板: 卓尼县| 英山县| 镇雄县| 博客| 普兰店市| 建瓯市| 兴国县| 巩留县| 余庆县| 项城市| 华宁县| 延津县| 正阳县| 克山县| 嘉义县| 新泰市| 基隆市| 上饶县| 双鸭山市| 大兴区| 内乡县| 景洪市| 嫩江县| 万州区| 偃师市| 买车| 湘潭市| 商洛市| 怀柔区| 西贡区| 华安县| 江北区| 崇明县| 浮梁县| 石柱| 鄂托克前旗| 靖西县| 宁城县| 克什克腾旗| 铁岭市| 阿巴嘎旗|