简体   繁体   中英

In Gmail, using Google Apps Script, is it possible to forward the TRANSLATED emails which I receive to another email address?

I receive many emails in Japanese everyday (I am living in Japan). Gmail automatically detect that the email is written in Japanese, so that one can click the "translate" button and get it translated. I would like to forward the translated email to another email address (or to a mailing list). It is easy to set up the mail forwarding, but when I do, only the original message (in Japanese) is forwarded. So my question is:

Is it possible, using Google Apps Scripts script (or any another tool), to forward the TRANSLATED emails which I receive to another email address?

I am a very beginner with Google tools, so any help is appreciated!

You can use the built-in LanguageApp service to translate text.

GmailApp.getInboxThreads().forEach((thread) => {
  thread
    .getMessages()
    .filter((message) => {
      return (
        message.getFrom().toLowerCase().indexOf("sender@example.com") !== -1
      );
    })
    .forEach((message) => {
      if (MailApp.getRemainingDailyQuota() > 1) {
        message.forward("email@example.com", {
          htmlBody: LanguageApp.translate(message.getBody(), "jp", "en"),
        });
      }
    });
});

To complete @Amit 's answer :

You can build your filter based on the sender using the .getFrom() method on a message instance. Here you can find an example.

GmailApp.getInboxThreads().forEach( thread => { 
    thread.getMessages().forEach( message => {
         if (message.getFrom() === "email2@example.com" { 
              message.forward("email@example.com", { htmlBody: LanguageApp.translate(message.getBody(), "jp", "en") }
         }
    });
});

Reference

GmailApp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM