我正在尝试将文件添加到azure函数发送的邮件中。
这是我的功能:
#r "Newtonsoft.Json"
#r "SendGrid"
#r "System.Web"
using System.Web;
using SendGrid.Helpers.Mail;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Http;
using System.IO;
using Microsoft.Azure.WebJobs.Host;
using System;
public static IActionResult Run(HttpRequest req, TraceWriter log, out SendGridMessage message)
{
log.Info("C# HTTP trigger function processed a request.");
string requestBody = new StreamReader(req.Body).ReadToEnd();
EmailContent data = JsonConvert.DeserializeObject<EmailContent>(requestBody);
if (data == null)
{
throw new ArgumentNullException("Data could not be null");
}
message = new SendGridMessage();
message.AddTo(data.Email);
message.SetFrom(new EmailAddress("no-reply@netflio.com"));
message.AddContent("text/html", HttpUtility.HtmlDecode(data.Body));
message.AddAttachment(data.AttachmentName, Convert.ToBase64String(data.Attachment));
message.SetSubject(data.Subject);
return (ActionResult)new OkObjectResult("OK");
}
public class EmailContent
{
public string Email { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public byte[] Attachment { get; set; }
public string AttachmentName { get; set; }
}
我的功能在我的本地计算机上工作得很好,但在我的azure函数上却不能。
文件丢失...