【问题标题】:How to work with Gmail attachments on Azure Logic App如何在 Azure Logic App 上使用 Gmail 附件
【发布时间】:2017-10-25 06:12:08
【问题描述】:

我创建了一个 Logic 应用程序,我从 Gmail 帐户接收电子邮件,我想将电子邮件的附件发布到我的 rest API。但我不明白我得到的是哪种类型的附件。我已经看到:如果我使用 Outlook.com 触发器,我会得到一个 base64String,但从 Gmail 我会得到别的东西。 是否有一个如何使用 Gmail 附件的示例。

【问题讨论】:

  • 您能否指定预期的行为?你需要什么格式发送到端点?
  • 是我的端点之一,所以我可以决定它。但通常我使用 base64 字符串

标签: azure gmail azure-logic-apps


【解决方案1】:

感谢输入 SahadevSinh。我已经像这样改变了我的工作流程:

在我的端点我这样做:

 public async System.Threading.Tasks.Task<MissionOutputDto> CreateMissionFromMail(HttpRequestMessage req)
    {
        string body = await req.Content.ReadAsStringAsync();
        dynamic fileData = JObject.Parse(body);
        string email = fileData.email;
        JArray files = fileData.files;

        string fileString = null;
        string fileName = null;
        string mimeType = null;

        foreach (dynamic file in files)
        {
            fileString = file.ContentBytes;
            fileName = file.Name;
            mimeType = file.ContentType;
        }

【讨论】:

    【解决方案2】:

    我必须举一个例子来告诉你如何获得 gmail 附件

    enter image description here

    1) 接收电子邮件触发:

    Step 1 details

    2) 获取电子邮件详细信息:

    Step 2 details

    3) 在 HTTP 请求中传递附件详细信息 Step 3 details

       [
      {
        "Name": "test (2).txt",
        "ContentBytes": "dGVzdA==",
        "ContentType": "text/plain; charset=\"US-ASCII\"; name=\"test (2).txt\"",
        "ContentId": "",
        "Size": 4
      },
      {
        "Name": "test (2) - Copy.txt",
        "ContentBytes": "dGVzdA==",
        "ContentType": "text/plain; charset=\"US-ASCII\"; name=\"test (2) - Copy.txt\"",
        "ContentId": "",
        "Size": 4
      }
    ]
    

    “contentbyte”:是 base64Srig

    WebAPI 更改:

    你已经创建了一个类来检索这个附件数据

    public class GmailAttechment
        {
            public string FileName { get; set; }
            public string ContentBytes { get; set; }
            public string ContentType { get; set; }
    
            public string ContentId { get; set; }
    
            public int Size { get; set; }
    
        }
    

    此类用于从您的请求中检索附件详细信息

    1. 将上述类添加到您的 webapi 请求参数中

      公共类 GetEmailDetails { 公共字符串文件 { 获取;放; }

          public string fileName { get; set; }
      
          public string from  { get; set; }
      
          public string mimeType { get; set; }
          **public List<GmailAttechment> GmailAttechmentList { get; set; }**
      }
      
      1. 动作示例

      public void GetGmailDetails(GetEmailDetails gmailDetails) { foreach(gmailDetails.GmailAttechmentList 中的变量项) { //这里可以获取所有文件内容 字符串 base6String = item.ContentBytes; } }

    【讨论】:

    • 我不确定,但我不能在 http 请求中使用带有名称附件的动态内容
    • 请查看编辑答案,如果您仍有疑问,请告诉我,因为我投入了宝贵的时间来解决这个问题
    • 我是新的代码示例,让您了解如何将 json 解析到列表中
    • 请查看并告诉我是否有任何问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 2021-08-02
    相关资源
    最近更新 更多