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

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"
}
主站蜘蛛池模板: 吉安市| 河北区| 东台市| 赣榆县| 广德县| 富裕县| 阜阳市| 榆社县| 乌恰县| 屏山县| 许昌县| 临海市| 霸州市| 漳州市| 临安市| 西乌| 秦安县| 武山县| 阿城市| 霍城县| 方正县| 惠来县| 平原县| 柘荣县| 台东市| 饶平县| 扎囊县| 汾阳市| 瓦房店市| 怀宁县| 龙里县| 宁强县| 鄂尔多斯市| 英德市| 松潘县| 通辽市| 桐乡市| 五河县| 潜江市| 巴青县| 禄劝|