KartikTalwar / gmail.js

Gmail JavaScript API
MIT License
3.74k stars 455 forks source link

[Question] Set/replace email's subject when opened from inbox view #709

Closed GTP95 closed 2 years ago

GTP95 commented 2 years ago

Greetings,

I'm trying to modify the data shown when a certain kind of email is opened from inbox view. After getting a reference to the email's DOM using the dedicated observer like so

gmail.observe.on("view_email", (domEmail) => {
[my code here]
}
);

I can change the email's body with

domEmail.body(bodyAsText);

But I'm failing to do the same for the email's subject. I tried both domEmail.email_subject(subject) and domEmail.subject(subject) but in both cases I get a TypeError saying that what I'm calling isn't a function. Is there a way to set or modify an email's subject? Thank you for your help,

GTP

josteink commented 2 years ago

Checking the source, the following might work?

const subjectNode = api.dom.email_subject();
subjectNode.text("New subject");
GTP95 commented 2 years ago

I think I'm not calling the right method:

const subjectNode = domEmail.email_subject();
subjectNode.text(subject);

gives TypeError: domEmail.email_subject is not a function.

const subjectNode = api.dom.email_subject();
subjectNode.text(subject);

gives ReferenceError: api is not defined and

const subjectNode = gmail.api.dom.email_subject();
subjectNode.text(subject);

gives TypeError: Cannot read properties of undefined (reading 'dom'). How should I call the right method?

Thank you for your help,

GTP

GTP95 commented 2 years ago

Never mind, I found that in my case I have to call it like this: const subjectNode = gmail.dom.email_subject();. Thank you for your help.