将电子邮件内容传递到Azure功能应用程序
我想将电子邮件的内容传递到我的函数应用程序中,以便删除HTML 我正在关注这一点,但我对收到的电子邮件是如何传入的感到困惑。我知道这是一个http请求,但不确定是哪一行处理这封电子邮件,然后我们可以做的工作 我们有我们的req,这是我们的http请求,所以我猜一旦我们在Azure中创建触发器,req就会直接传入 下面是提供的示例代码:将电子邮件内容传递到Azure功能应用程序,azure,.net-core,azure-functions,Azure,.net Core,Azure Functions,我想将电子邮件的内容传递到我的函数应用程序中,以便删除HTML 我正在关注这一点,但我对收到的电子邮件是如何传入的感到困惑。我知道这是一个http请求,但不确定是哪一行处理这封电子邮件,然后我们可以做的工作 我们有我们的req,这是我们的http请求,所以我猜一旦我们在Azure中创建触发器,req就会直接传入 下面是提供的示例代码: #r "Newtonsoft.Json" using System.Net; using Microsoft.AspNetCore.Mvc;
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log) {
log.LogInformation("HttpWebhook triggered");
// Parse query parameter
string emailBodyContent = await new StreamReader(req.Body).ReadToEndAsync();
// Replace HTML with other characters
string updatedBody = Regex.Replace(emailBodyContent, "<.*?>", string.Empty);
updatedBody = updatedBody.Replace("\\r\\n", " ");
updatedBody = updatedBody.Replace(@" ", " ");
// Return cleaned text
return (ActionResult)new OkObjectResult(new { updatedBody });
}
#r“Newtonsoft.Json”
Net系统;
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.Extensions.Primitives;
使用Newtonsoft.Json;
使用System.Text.RegularExpressions;
公共静态异步任务运行(HttpRequest请求,ILogger日志){
log.LogInformation(“HttpWebhook触发”);
//解析查询参数
string emailBodyContent=等待新的StreamReader(req.Body).ReadToEndAsync();
//用其他字符替换HTML
string updatedBody=Regex.Replace(emailBodyContent,“”,string.Empty);
updatedBody=updatedBody.Replace(“\\r\\n”,”);
updatedBody=updatedBody.Replace(@“”);
//返回清除的文本
返回(ActionResult)新的OkObjectResult(新的{updatedBody});
}
req.Body
是向函数发送POST
请求时HTTP消息的正文。因此,请求的正文应该包含您的整个电子邮件内容,然后您就可以开始了
实际上,您的注释//解析查询参数是错误的。它不是解析查询参数,而是读取HTTP消息体
顺便说一句:我建议你帮自己一个忙,不要在Azure门户中编写C#Script函数,而是在本地编写和测试它们,例如在VS代码中,然后编译它们并将它们正确部署到Azure函数中。干杯!是的,我发现在门户网站上写作有点像噩梦。谢谢你的建议,朋友