# Node Red emailer and 0auth2- "ReferenceError: msg is not defined" function check

**URL:** https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178
**Category:** General
**Created:** [6 March 2024 05:50 UTC](https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178 "2024-03-06T05:50:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hadwll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hadwll/32/89020_2.png) [@hadwll](https://discourse.nodered.org/u/hadwll)
#### Post date: [6 March 2024 05:50 UTC](https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178/1 "2024-03-06T05:50:54Z")

</div>

I have setup an email node with Oauth2 authentication, that side of it is working, I have got the access token ok.

I am getting an error on deploy when from the email node itself. ("ReferenceError: msg is not defined") This is only when I enable the Oauth2 authentication in the email node. so perhaps there is an issue in my message it is not properly defined for the email node? Ive tried a couple/alot of different format options havent managed as yet. What am I missing?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/1568afd91df1edf3b6d4ad32b623530fdba7f6b3.png)

```auto
// Extract necessary values from input msg
let access_token = msg.oauth2Response.access_token;

// Create a new message object with only the necessary properties
let newMsg = {
    payload: 'this is a dummy email',
    topic: 'some title',
    oauth2Response: {
        access_token: access_token
    }
};

// Return the new message object
return newMsg;

```

also tried this function to create the email.

```auto
// Add payload and topic properties to the msg object

msg.payload = 'this is a dummy email';

msg.topic = 'some title';

// Return the modified msg object

return msg;

```

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [6 March 2024 17:08 UTC](https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178/2 "2024-03-06T17:08:43Z")

</div>

@hadwll

I think this is a bug with the node - or at least its assumptions are incorrect.

@dceejay @Steve-Mcl

The node initializer is expecting an `msg` property - but during init, it will not exist?

**C'tor**

> <https://github.com/node-red/node-red-nodes/blob/fd027aa95a5c0847596a96705c3a05c969ae39a9/social/email/61-email.js#L30>

**Trying to use** `msg` **in there**

> <https://github.com/node-red/node-red-nodes/blob/fd027aa95a5c0847596a96705c3a05c969ae39a9/social/email/61-email.js#L82>

This would explain the error occurring during deploy?

IMO adjusting SMTP auth methods should be occurring on `input` ?  
certainly if auth values are to be taken from `msg`

I might be a little rusty - so forgive me, if i'm just talking rubbish

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [6 March 2024 17:14 UTC](https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178/3 "2024-03-06T17:14:20Z")

</div>

It certainly does look like a bug was introduced in [XOAuth2 for Email-In node by wooferguy · Pull Request #975 · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/pull/975)

@hadwll - could you please [raise an issue](https://github.com/node-red/node-red-nodes/issues/new/choose) and link back to this thread?

---

<div class="post-metadata">

### Author: ![hadwll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hadwll/32/89020_2.png) [@hadwll](https://discourse.nodered.org/u/hadwll)
#### Post date: [7 March 2024 05:58 UTC](https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178/4 "2024-03-07T05:58:15Z")

</div>

> [@Steve-Mcl](#):
>
> It certainly does look like a bug was introduced in [XOAuth2 for Email-In node by wooferguy · Pull Request #975 · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/pull/975)
> 
> @hadwll - could you please [raise an issue](https://github.com/node-red/node-red-nodes/issues/new/choose) and link back to this thread?

yes, no problem, The issue is here [node-red-node-email, send node "ReferenceError: msg is not defined" on deploy · Issue #1054 · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/issues/1054)

I wanted to ask then is this stopping my email sending?

As it is not working working for me and not presenting any error, I placed a catch node but it shows nothing as well.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 June 2024 05:58 UTC](https://discourse.nodered.org/t/node-red-emailer-and-0auth2-referenceerror-msg-is-not-defined-function-check/86178/5 "2024-06-05T05:58:16Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
