如何在 Azure 逻辑应用程序上使用 Gmail 附件
How to work with Gmail attachments on Azure Logic App
我创建了一个 Logic 应用程序,我可以在其中接收来自 Gmail 帐户的电子邮件,我想 post 将电子邮件的附件发送到我的邮箱 API。但是我不明白我作为附件获得的是哪种类型。我已经看到:如果我使用 Outlook.com 触发器,我会得到一个 base64String 但从 Gmail 我会得到其他东西。
是否有使用 Gmail 附件的示例。
我必须通过一个例子来向您展示如何获取 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" : 是 base64Strig
WebAPI 更改:
您又创建了一个 class 来检索此附件数据
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; }
}
此 class 用于从您的请求中检索附件详细信息
将上面的class添加到你的webapi请求参数中
public class GetEmailDetails
{
public 字符串文件 { 得到;放; }
public string fileName { get; set; }
public string from { get; set; }
public string mimeType { get; set; }
**public List<GmailAttechment> GmailAttechmentList { get; set; }**
}
- 行动示例
public void GetGmailDetails(GetEmailDetails gmailDetails)
{
foreach(gmailDetails.GmailAttechmentList 中的 var 项目)
{
//这里可以获取所有文件内容
字符串 base6String = item.ContentBytes;
}
}
感谢 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;
}
我创建了一个 Logic 应用程序,我可以在其中接收来自 Gmail 帐户的电子邮件,我想 post 将电子邮件的附件发送到我的邮箱 API。但是我不明白我作为附件获得的是哪种类型。我已经看到:如果我使用 Outlook.com 触发器,我会得到一个 base64String 但从 Gmail 我会得到其他东西。 是否有使用 Gmail 附件的示例。
我必须通过一个例子来向您展示如何获取 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" : 是 base64Strig
WebAPI 更改:
您又创建了一个 class 来检索此附件数据
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; }
}
此 class 用于从您的请求中检索附件详细信息
将上面的class添加到你的webapi请求参数中
public class GetEmailDetails { public 字符串文件 { 得到;放; }
public string fileName { get; set; } public string from { get; set; } public string mimeType { get; set; } **public List<GmailAttechment> GmailAttechmentList { get; set; }** }
- 行动示例
public void GetGmailDetails(GetEmailDetails gmailDetails) { foreach(gmailDetails.GmailAttechmentList 中的 var 项目) { //这里可以获取所有文件内容 字符串 base6String = item.ContentBytes; } }
感谢 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;
}