Home>
I am a beginner.
Modified the system to extract and fill in unread emails coming from email forms in a spreadsheet,
Based on the following advice, I thought it worked, but now I have extracted not only unread but also read (extracted/filled).
https://www.tutorialfor.com/go.php?id=225631
I know that the problem is the part that I modified, but I have a clue how to fix it.
Can someone teach me? . .
Gmail wants to extract only unread, but already read (extracted/filled) ones are now inserted.
Example
AAAAA
(Send BBBBB by email form)
↓
AAAAA
AAAAA
BBBBB
(Send more CCCCC via email form)
↓
AAAAA
AAAAA
BBBBB
AAAAA
BBBBB
CCCCC
Ideal form
AAAAA
BBBBB
CCCCC
Corrections marked around
>>>>>><<<<
Since "push to resultArr as many times as msgs.length in the returnData function", is it ok if we can associate thread or length (variable) with msgs in the returnData function? Both ...
I ’m a beginner, so I ’m sorry.
function getMailandInsert () {
var sheet = SpreadsheetApp.getActiveSheet ();
// start potision
var start = 0;
// Maximum number of emails to retrieve
var max = 5;
// number of data columns to insert into the spreadsheet
var insertCol = 6;
// Get incoming email that matches the conditions
var threads = GmailApp.search ('is: unread from: ([email protected]) subject: (wakaran)', start, max);
// number of threads matching the condition
var length = threads.length;
// The last row of the sheet where the data will be saved. That is, the insertion start position
var row = sheet.getLastRow () + 1;
// Array for storing the acquired mail contents
var resultArr = new Array ();
for (var n in threads) {
var the = threads [n];
// get mail in thread
var msgs = the.getMessages ();
// Analyze the mail in the thread and store it in resultArr
returnData (msgs, resultArr);
// Mark the acquired thread as read
the.markRead ();
Utilities.sleep (1000);
}
if (length! = 0) {
sheet.getRange (row, 1, msgs.length, insertCol) .setValues (resultArr);// save data
// The contents of getRange are (final line + 1,1, number of threads, 6)
//>>>>>>>>>>length->msgs.length modified<<<<<<This is a problem. The cause is ignoring unread. The length value must match the resultArr value as it is.
}
}
function returnData (msgs, resArray) {
for (m in msgs) {
try {
var tempArray = new Array ();
var msg = msgs [m];
// email date
var date = msg.getDate ();
// E-mail sender address
var from = msg.getFrom ();
// Email subject
var subject = msg.getSubject ();
// Get email body with PlainBody
var body = msg.getPlainBody ();
// Parse the body with an XML parser
var xml = XmlService.parse (body);
// Get the root element of the XML analysis result
var root = xml.getRootElement ();
// Specify each child element in XML and get its value.
var hinichi = root.getChild ("hinichi"). getText ();
var zzz = root.getChild ("zzz"). getText ();
var xxx = root.getChild ("xxx"). getText ();
var ddd = root.getChild ("ddd"). getText ();
var vvv = root.getChild ("vvv"). getText ();
var etc = root.getChild ("etc"). getText ();
// store each value in an array
tempArray [0] = hinichi;
tempArray [1] = zzz;
tempArray [2] = ddd;
tempArray [3] = eisei;
tempArray [4] = vvv;
tempArray [5] = etc;
// add array to the end with push
resArray.push (tempArray);
} catch (e) {
Logger.log ("Error:" + e);
}
}
}
Supplemental information (FW/tool version etc.)
chrome latest version
-
Answer # 1
Related articles
- javascript - notification to gmail when updating gas spreadsheet
- javascript - in the rock-paper-scissors program, the error "com is not defined" appeared in the conditional branch of
- javascript - i want to output the data obtained from the api to a spreadsheet and summarize it in a table for easy viewing
- i want to create an api program that links json, ajax, javascript, java
- javascript - i want to make a program that displays the newest one by looking at the date when the name is covered in the associ
- php - i want to embed a spreadsheet program like excel into a web page
- javascript - i want to get gmail attachments using nodejs
- i want to post only unread gmail to a spreadsheet
- html javascript program operation order
- javascript - gas: i want to get a range of cells in a spreadsheet and replace the values according to the conditions
- i am writing a program that creates palindromes with javascript (* it is not a program that judges palindromes)
- javascript - i want to make a copy using a script in a spreadsheet
- javascript - [gas] i want to select the spreadsheet id on the html side and pass it to the function
- javascript - cannot call python program by post communication using aws amplify
- javascript - [gas] write to a spreadsheet using a shortcut
- javascript - i don't want to display the memo field of the cell when converting the spreadsheet to pdf
- javascript - i want to get spreadsheet data in json using gus
- javascript - [gas] a program that maintains variables
- javascript - [gas] how to write a program that gets the latest message and branches
- javascript - i want to make a btc automatic trading program using ccxt, forever, but it doesn't work 24 hours a day
A thread that is already read will be unread if a new message is received.
Check
GmailMessage # isUnread
and ignore the read.