如何提取反弹邮件的全身内容? [英] How to extract full body content of a Bounced back email?
问题描述
上面的截图是收到的退回邮件的示例。
我使用以下代码来提取邮件的正文。
function test )
{
var BouncedEmails = GmailApp.search(label:test以下消息无法投递);
for(var i = 0; i< BouncedEmails.length; i ++)
{
var Gmessage = GmailApp.getMessagesForThread(BouncedEmails [i]);
for(var j = 0; j< Gmessage.length; j ++)
{
var body = Gmessage [j] .getPlainBody();
Logger.log(body);
}
}
}
但是当我这样做,我得到以下输出。
正如您所看到的,Body的最后一部分缺少,即:
我也尝试使用:
var body = Gmessage [j] .getBody();
而不是GetPlainBody(),但输出仍然相同。
使用:
var body = Gmessage [j] .getRawContent();
我把它作为输出的缺失部分,这在我看来是一种编码。
所以我的问题是,我如何提取反弹邮件的完整内容? / p>
谢谢。
我终于找到了我自己的答案问题。
这对我来说很有用,对于我们这个星球上的任何人来说都会有用的。
function test()
{
var BouncedEmails = GmailApp.search(label:test以下消息无法传送);
for(var i = 0; i< BouncedEmails.length; i ++)
{
var threadId = BouncedEmails [i] .getId();
var id = Session.getEffectiveUser()。getEmail();
var body = Gmail.Users.Threads.get(id,threadId,{format:'full'});
var messages = body.messages;
var payLoad = messages [0] .payload.parts [2];
var string = JSON.stringify(payLoad);
Logger.log(string);
}
}
@AmitAgarwal和@ShyamKansagra提供的解决方案也在某些情况下工作,但使用哪种解决方案取决于您的具体要求。
The above screenshot is the sample of the Bounced Back Mail received.
I'm using the following code to extract the Body of the mail.
function test()
{
var BouncedEmails = GmailApp.search("label:test The following message was undeliverable ");
for( var i=0;i<BouncedEmails.length;i++)
{
var Gmessage = GmailApp.getMessagesForThread(BouncedEmails[i]);
for(var j=0;j<Gmessage.length;j++)
{
var body = Gmessage[j].getPlainBody();
Logger.log(body);
}
}
}
But when I am doing this, I got the following output.
As you can see the last part of the Body is missing, that is :
I also tried using :
var body = Gmessage[j].getBody();
instead of "GetPlainBody()" but the output was still the same.
On using :
var body = Gmessage[j].getRawContent();
I got this as output for the missing part, which seems to me as some sort of encoding.
So my question is, how do i extract the full content of the Bounced Back Mail?
Thank You.
I finally found the answer to my own question.
This has worked for me and will pretty much work for anyone on our planet.
function test()
{
var BouncedEmails = GmailApp.search("label:test The following message was undeliverable ");
for( var i=0;i<BouncedEmails.length;i++)
{
var threadId = BouncedEmails[i].getId();
var id = Session.getEffectiveUser().getEmail();
var body = Gmail.Users.Threads.get(id, threadId, {format : 'full'});
var messages = body.messages;
var payLoad = messages[0].payload.parts[2];
var string = JSON.stringify(payLoad);
Logger.log(string);
}
}
The solutions provided by @AmitAgarwal and @ShyamKansagra would also work for some cases, but which solution to use depends on what is your exact requirement.
这篇关于如何提取反弹邮件的全身内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!