@מעמד-מוצלח מסכים בכל מילה עם @צבי-ש, אבל יש לי משהו שהכנתי פעם לחבר, זה קצת יותר מ'כל התחלה של קוד כזה'
אני זוכר שהיה לו תלונה בקשר לשרשורים, מעיון קליל בקוד נראה שזה בגלל שכל הודעה נשלחת בנפרד, שים לב שההודעות נשארות מסומנות בתווית גם לאחר השליחה שלהם למייל השני.
// Forwards The Emails By abaye
const label = 'move';
const email = 'email@gmail.com';
function sendEmails() {
let threads = GmailApp.search(`label:${label}`);
threads.forEach(thread => {
let messages = thread.getMessages();
messages.forEach(message => {
let senderName = message.getFrom();
let subject = message.getSubject();
let body = message.getPlainBody();
let attachments = message.getAttachments();
let emailContent = `שולח ההודעה: ${senderName}\nהנושא: ${subject}\n\nתוכן ההודעה:\n${body}`;
GmailApp.sendEmail(
email,
`Fwd: ${subject}`,
emailContent,
{
attachments: attachments,
name: "הועבר מהמייל של מוישי"
}
);
});
});
}