【问题标题】:Azure function send email with attachmentAzure 功能发送带附件的电子邮件
【发布时间】:2021-04-01 17:31:15
【问题描述】:

我写了一个用于发送电子邮件的 Azure 函数,这是定义

    [FunctionName("SendEmail")]
    public static async Task<ApiResult> SendEmailAsync(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
    SendEmailDataInput input,
    [ServiceBus("sb", Connection = "ServiceBusConnection", EntityType = EntityType.Topic)] 
    IAsyncCollector<BrokeredMessage> collector, ILogger log)
    {
        (...)
    }

我正在使用 Postman 测试该功能,如果我在“原始数据”部分中放入与 SendEmailDataInput 类对应的 Json 结构,它就可以工作。但我还想在电子邮件中添加附件。那么如何修改函数定义,以及如何在 Postman 中对其进行测试,以便发送包含电子邮件数据 + 文件的 Json?

【问题讨论】:

    标签: azure-functions postman


    【解决方案1】:

    我在这里找到了答案:No MediaTypeFormatter is available to read an object of type 'HttpRequestMessage' from content with media type 'multipart/form-data'

    关键是将请求作为HttpRequestMessage(而不是我的类SendEmailDataInput),这样我可以获取不同格式的表单数据。

    【讨论】:

      猜你喜欢
      • 2013-04-14
      • 2023-03-10
      • 2021-09-22
      • 2015-08-28
      • 2014-04-23
      • 2019-03-09
      • 2015-09-09
      相关资源
      最近更新 更多