1
00:00:00,960 --> 00:00:05,160
So in this lesson, we're going to be setting up the end points and what the end point is going to do

2
00:00:05,160 --> 00:00:11,400
is it's Google Apps script, so it's going to track information into the spreadsheets, the email,

3
00:00:11,580 --> 00:00:18,600
the user and the message as well as it's going to send us an email to our email account with the parameters

4
00:00:18,600 --> 00:00:20,140
from the input form.

5
00:00:20,490 --> 00:00:21,770
So let's go ahead and send it.

6
00:00:22,080 --> 00:00:25,080
So notice we are on the local machine we had sent.

7
00:00:27,720 --> 00:00:34,050
The content that we're sending over gets deposited into the spreadsheet, we also get indication that

8
00:00:34,050 --> 00:00:35,640
the message has been sent.

9
00:00:36,000 --> 00:00:38,680
Go over to the inbox within the inbox.

10
00:00:39,210 --> 00:00:41,960
There's our message that was coming from the Web form.

11
00:00:42,330 --> 00:00:46,080
So any changes to the content here?

12
00:00:50,250 --> 00:00:58,530
Will also be sent over and that will send another message over to our email address so you could use

13
00:00:58,530 --> 00:01:03,540
this as a way to have a quick contact form on your website.

14
00:01:03,720 --> 00:01:08,180
So let's create the endpoint for this for this lesson.

15
00:01:08,190 --> 00:01:13,980
You are going to need to have a Google account so you can just use a Gmail account or Google account.

16
00:01:14,280 --> 00:01:20,280
And we're going to be selecting the data and returning it back and actually sending an email.

17
00:01:20,430 --> 00:01:23,970
And this is all going to be done with the backend code on Google Apps script.

18
00:01:24,210 --> 00:01:29,190
So if you're not familiar with Google Apps script, this is similar to code to JavaScript.

19
00:01:29,190 --> 00:01:35,190
Essentially, it's the same as JavaScript with a bunch of custom methods that allow you to connect calendar

20
00:01:35,190 --> 00:01:41,730
docs, drive Gmail sheet slides and all of your favorite Google Apps together to do some really pretty

21
00:01:41,730 --> 00:01:42,660
cool functionality.

22
00:01:42,930 --> 00:01:47,700
So it's modern JavaScript platform in the cloud, the ideas on the cloud as well.

23
00:01:47,850 --> 00:01:52,080
So in order to access it, all you need is a Google account so you can also access it with the free

24
00:01:52,230 --> 00:01:52,850
accounts.

25
00:01:53,190 --> 00:01:57,770
There's two different types of scripts to create their standalone and bound scripts.

26
00:01:58,020 --> 00:02:01,050
So we are going to be creating a bound script within the spreadsheet.

27
00:02:01,500 --> 00:02:08,610
In addition, you can also find out more information about Google off script and developers dot Google

28
00:02:08,610 --> 00:02:10,410
dot com, for example, script.

29
00:02:10,620 --> 00:02:16,740
And we are going to be using the mail function in order to send the email and track the information

30
00:02:16,740 --> 00:02:21,450
that's being submitted using the post request to our web app Endpoint.

31
00:02:21,720 --> 00:02:22,820
So let's get started.

32
00:02:22,830 --> 00:02:30,220
Open up here, Google Drive and from there you can select new and from the drop down menu and selecting

33
00:02:30,270 --> 00:02:31,290
new sheets.

34
00:02:31,450 --> 00:02:36,840
So it's creating a brand new sheet object and you can access apps, script from sheets, from docs,

35
00:02:37,020 --> 00:02:39,240
from slides, and I'll show you how to do that.

36
00:02:40,110 --> 00:02:44,100
So this is give it a name contact info.

37
00:02:46,050 --> 00:02:51,720
And so this is going to be depositing some of the contact form requests into the spreadsheet.

38
00:02:51,720 --> 00:02:55,070
And I'll show you how to do that as well and send it as an email.

39
00:02:55,620 --> 00:02:59,820
And then once you've given it a name, you don't have to actually do anything else.

40
00:02:59,830 --> 00:03:03,050
You can go to Tools and under script editor.

41
00:03:03,450 --> 00:03:10,470
This is going to open up the online editor where we can write our Google Apps script and with the Google

42
00:03:10,470 --> 00:03:11,310
Apps scripts.

43
00:03:11,310 --> 00:03:14,850
So I'll just give this project a name as well.

44
00:03:16,770 --> 00:03:20,490
And this is going to be contact tester.

45
00:03:20,760 --> 00:03:25,920
And there's also if you want to go to script dot Google dot com forward slash home.

46
00:03:26,220 --> 00:03:26,940
So that's the home.

47
00:03:26,940 --> 00:03:30,240
And that will list out all of the Google scripts that you currently have.

48
00:03:31,830 --> 00:03:38,610
So there are some default functions within Google Apps script, and one of them is to deploy a Web app.

49
00:03:38,850 --> 00:03:47,280
So it uses a custom function and the function that generates the Web app is called Do Get and you can

50
00:03:47,280 --> 00:03:50,340
pass in your event parameters there.

51
00:03:50,910 --> 00:03:56,670
So the same thing as what you would expect with JavaScript where we create functions and then these

52
00:03:56,670 --> 00:04:02,520
functions run the code blocks and produce the functionality within Google Apps script.

53
00:04:02,820 --> 00:04:06,500
And there's a few different methods with Google Apps script.

54
00:04:06,870 --> 00:04:15,480
So one of them to logout content, you can do logger log and that will logout content into the log.

55
00:04:15,810 --> 00:04:23,100
So when we do run the script in order to run the script, there's a run the selected function option

56
00:04:23,100 --> 00:04:25,770
here in the navigation menu.

57
00:04:26,070 --> 00:04:29,300
And then from the dropdown list, you can select the function that you want to run.

58
00:04:29,700 --> 00:04:37,380
So once we run the function, the execution log will pop up and for right now it just will have the

59
00:04:37,470 --> 00:04:39,750
logger and the logging information.

60
00:04:40,020 --> 00:04:43,620
And this is going to actually function the same way as the console log.

61
00:04:44,370 --> 00:04:47,400
So now with the newer version, you can also do console like.

62
00:04:47,670 --> 00:04:54,360
So we're outputting the value of Halo into the log and let's construct some content.

63
00:04:56,200 --> 00:05:03,490
So this is just some test content and then there's a number of services and the one that we want to

64
00:05:03,490 --> 00:05:05,200
use is the content service.

65
00:05:05,770 --> 00:05:08,350
So this one can create text output.

66
00:05:08,590 --> 00:05:10,480
And this is also where we can create the.

67
00:05:11,850 --> 00:05:17,980
Output, the Jason output, and let's create a temporary object.

68
00:05:18,960 --> 00:05:19,980
Now, you don't have to do this.

69
00:05:19,990 --> 00:05:24,770
This is just to demonstrate how Google Apps script is going to handle the content that's coming in.

70
00:05:25,410 --> 00:05:29,490
So we might have a number of pieces of content within the object.

71
00:05:30,830 --> 00:05:33,830
And within the parameters.

72
00:05:36,870 --> 00:05:41,950
So parameter and then this can have a value of tests or something like that.

73
00:05:43,260 --> 00:05:49,740
So if we want to output the object information, you can use the JSON string of fine Seimas JavaScript

74
00:05:50,250 --> 00:05:58,260
in order to string a fighter object and just do the console log and you could also do the logger log.

75
00:05:58,890 --> 00:06:01,020
So this is what we're actually going to be outputting.

76
00:06:02,970 --> 00:06:04,250
So run that one more time.

77
00:06:04,770 --> 00:06:10,890
And so now we've got the string of object and this is actually what we want to output back to the page.

78
00:06:11,160 --> 00:06:18,690
So we want to take the contents of the event object that's being passed in to the do get function and

79
00:06:18,690 --> 00:06:25,110
string A that we're going to log it out as output and then we're going to be returning that information

80
00:06:25,110 --> 00:06:29,660
back to the user for the Web page.

81
00:06:30,180 --> 00:06:36,420
And it's expecting the do get when it runs the web up, it does have a return function so you can return

82
00:06:36,420 --> 00:06:37,070
content.

83
00:06:37,320 --> 00:06:42,050
And in this case, we're going to be returning that object that's created by content service, create

84
00:06:42,060 --> 00:06:46,540
text output and the text output that we want to create is going to be within output.

85
00:06:48,270 --> 00:06:54,330
So having done all of that, you can also shorten this just to do a return of the content service,

86
00:06:54,330 --> 00:06:57,750
text output, JSON string of IHI parameters.

87
00:06:57,750 --> 00:06:59,160
So I'll add that.

88
00:07:00,820 --> 00:07:08,680
The most important part is that you're returning something for this and that as well, you've got some

89
00:07:08,680 --> 00:07:14,230
type of content that you're constructing using the different methods that are available to create the

90
00:07:14,230 --> 00:07:14,680
output.

91
00:07:15,730 --> 00:07:18,760
So this one statement is actually all we need.

92
00:07:19,330 --> 00:07:23,530
But I'll keep this stuff in here so that we can take a closer look at it.

93
00:07:23,530 --> 00:07:25,220
If we want to debug it, we can debug it.

94
00:07:25,960 --> 00:07:32,410
So now, in order to create the Web app, the next step is once you've got the do get function and this

95
00:07:32,410 --> 00:07:37,390
is the most important part, because without this, you're not going to have a Web webapp and then also

96
00:07:37,390 --> 00:07:41,500
make sure that your returning content, if you're not returning content, it'll throw an error and it'll

97
00:07:41,500 --> 00:07:43,030
ask you to return some content.

98
00:07:43,450 --> 00:07:48,610
So the top right hand side, there's a blue button and that is the deployment button.

99
00:07:49,570 --> 00:07:55,100
So this will give you select the type of deployments and we want to create a Web app.

100
00:07:56,050 --> 00:08:02,920
So this is the contact tester and select the app that you want to execute us.

101
00:08:03,100 --> 00:08:09,680
And since we do want to send an email, you need to execute it as whatever Google account.

102
00:08:09,910 --> 00:08:17,980
So in this case, we're going to be sending that email from my account over to wherever we're specifying.

103
00:08:17,980 --> 00:08:19,780
So the email is going to be originating.

104
00:08:19,990 --> 00:08:24,910
So this is the same thing that you do with any backend code where you need to send the email from the

105
00:08:24,910 --> 00:08:25,450
server.

106
00:08:25,600 --> 00:08:28,030
So you need to have the server mail client setup.

107
00:08:28,540 --> 00:08:34,150
So setting up the account is can also provide the permissions for it and then who has access to it.

108
00:08:34,480 --> 00:08:41,090
And we do want to have this open so we can set this up and just leave it to anyone.

109
00:08:41,800 --> 00:08:47,210
So deploying the new deployment is going to construct an endpoint for us.

110
00:08:47,230 --> 00:08:49,900
So this is the endpoint, executable endpoint.

111
00:08:49,900 --> 00:08:51,060
And I know it's fairly long.

112
00:08:53,080 --> 00:08:58,610
You can copy this content and it's also got a deployment ID and so on.

113
00:08:58,750 --> 00:09:05,410
So once you've copied the euro, you've actually deployed the application and now you can go to that

114
00:09:05,410 --> 00:09:08,080
endpoint and you're going to see some output here.

115
00:09:08,110 --> 00:09:12,690
So right now, we haven't passed in any parameters into the string.

116
00:09:13,120 --> 00:09:22,770
If we do something like ID equals one hundred and test equals tester, it will output those as parameters.

117
00:09:23,350 --> 00:09:27,070
So this is where we can pick up using the get method.

118
00:09:27,490 --> 00:09:34,900
So if we are using get we're sending this information over to the server within the request parameters.

119
00:09:36,100 --> 00:09:43,960
And if we go into the execution log, we're not actually looking out the content that is like that when

120
00:09:43,960 --> 00:09:45,020
we're making the request.

121
00:09:45,160 --> 00:09:50,060
So it does make it a little bit hard to debug where we can't just launch the function to do the debug.

122
00:09:50,380 --> 00:09:51,670
So just keep that in mind.

123
00:09:52,510 --> 00:09:54,810
So the endpoint is going to be actually the same.

124
00:09:55,030 --> 00:10:03,400
So open up the Web application and I'm going to update you URL to be the new executable endpoint you

125
00:10:03,400 --> 00:10:03,680
URL.

126
00:10:04,900 --> 00:10:10,870
And right now it's still going to throw an error because it's not that doesn't have a post and we're

127
00:10:10,870 --> 00:10:13,080
trying to post to somewhere where there's no due post.

128
00:10:13,690 --> 00:10:18,730
So if you do run into the course error, this typically with Google Apps script is going to be an error

129
00:10:18,880 --> 00:10:20,470
with the script itself.

130
00:10:21,130 --> 00:10:25,330
So let's update and we'll add in the new post method.

131
00:10:26,290 --> 00:10:35,080
And what do Post does is the same as you get, but it picks up any post method requests to the server.

132
00:10:35,680 --> 00:10:43,420
And we can also do the same where we outputting and returning back the contents every time you do make

133
00:10:43,420 --> 00:10:54,880
some updates to it, we want to make sure that we redeploy the application as otherwise the properties

134
00:10:54,900 --> 00:10:56,540
won't won't be updated.

135
00:10:56,860 --> 00:11:00,760
So this is version two and just do a deploy of it.

136
00:11:01,300 --> 00:11:02,170
Same web.

137
00:11:02,170 --> 00:11:04,150
You are also you can copy it here at this point.

138
00:11:04,390 --> 00:11:10,930
And if you ever do need to get the web you URL, you can always go over to deploy, manage deployments.

139
00:11:11,230 --> 00:11:16,960
And from here you can pick up the web app, you URL as well, and you can change the permissions and

140
00:11:16,960 --> 00:11:17,960
then you could redeploy it.

141
00:11:18,760 --> 00:11:24,340
So let's try that one more time, go back to our application and hit send.

142
00:11:24,640 --> 00:11:31,870
And this time we're actually getting back the post data so we're successfully able to send our post

143
00:11:31,900 --> 00:11:34,020
data over to the server side.

144
00:11:34,390 --> 00:11:41,320
So now it's a matter of picking up that post data within the Google side so we can pass the contents.

145
00:11:44,240 --> 00:11:51,320
And this is within the post data, within the event parameter, the post data contents, and all it's

146
00:11:51,320 --> 00:11:57,950
doing is it's just returning back whatever we're sending through so you can update these values do ascend

147
00:11:57,950 --> 00:12:01,880
and it's going to send the content and then it's also going to return it back.

148
00:12:02,240 --> 00:12:08,120
So this is the part that we're looking for is within the post data and we want to return back just the

149
00:12:08,120 --> 00:12:15,790
post data to the user so it go back into the script editor and let's create a JavaScript object.

150
00:12:15,800 --> 00:12:18,830
So Jason and I add some spaces to move it up.

151
00:12:19,400 --> 00:12:23,360
So using JSON pass is just as we would with JavaScript.

152
00:12:23,870 --> 00:12:29,120
We can take the EA post data contents.

153
00:12:30,890 --> 00:12:38,300
So the same that we saw within the request parameters that were returning back so we can pass it and

154
00:12:38,300 --> 00:12:41,380
that's going to allow us to once again use it as an object.

155
00:12:41,810 --> 00:12:49,730
So if we only want to return back the actual object data that we're sending over, so now we can use

156
00:12:49,730 --> 00:12:57,490
it, we can get the various values so we can get the email and so on, and we can use it within that

157
00:12:57,500 --> 00:12:58,690
Google off script code.

158
00:12:59,360 --> 00:13:01,400
So just did another update to it.

159
00:13:01,820 --> 00:13:10,880
And now let's set this as V three for our application, redeploy it and now want to make a request to

160
00:13:10,880 --> 00:13:12,710
the endpoint so we can clear it.

161
00:13:13,310 --> 00:13:16,370
And you don't have to refresh because this is a client site code.

162
00:13:16,550 --> 00:13:19,010
So we're getting exactly the object back.

163
00:13:19,370 --> 00:13:24,020
And that means that we can also use this object within our script.

164
00:13:24,470 --> 00:13:30,860
So going back once again to the script, let's add the content into our spreadsheet.

165
00:13:31,580 --> 00:13:38,960
So with the spreadsheets, once it's connected, every Google document will have its own unique ID.

166
00:13:39,290 --> 00:13:43,150
Easiest way to get the idea is to go within the Web URL.

167
00:13:43,790 --> 00:13:45,890
So let's take the contents there.

168
00:13:46,160 --> 00:13:51,230
And this is also how you can create a log and so on, adding content into the spreadsheet.

169
00:13:51,740 --> 00:13:57,590
So we're going to select the spreadsheet and there is a class for that.

170
00:13:57,860 --> 00:13:59,180
So it's the spreadsheet app.

171
00:14:00,080 --> 00:14:08,780
And here we want to get so we can get the active spreadsheet because we are connected to it with bound

172
00:14:08,790 --> 00:14:17,390
script or we can also open by it ID and usually I do prefer to open by ID, so let's create another

173
00:14:17,750 --> 00:14:21,050
variable name and that's just going to be the ID.

174
00:14:21,350 --> 00:14:22,640
So open by ID.

175
00:14:22,760 --> 00:14:30,670
So we specify the ID of the object and that's going to be the spreadsheet and to get the sheet itself

176
00:14:31,310 --> 00:14:33,170
now that we've got a spreadsheet object.

177
00:14:36,150 --> 00:14:38,970
We can get sheet by.

178
00:14:45,340 --> 00:14:53,260
Name, so let's select the sheet and we've got it as sheet one, so that will select the sheet object

179
00:14:53,260 --> 00:14:56,950
for us and then for the sheet itself.

180
00:14:59,040 --> 00:15:09,150
We can append a row of content to it, and now that we've got content within the JSON object, if we

181
00:15:09,150 --> 00:15:17,420
want to turn this JSON object into an array or for now, what we can do is we can just track the contents

182
00:15:17,430 --> 00:15:26,040
and so let's redeploy it because we've made changes to it webapp and select it and we'll do a version

183
00:15:26,040 --> 00:15:26,400
four.

184
00:15:27,780 --> 00:15:36,360
So redeploy it and we're going to have to accept permissions so authorizing the webapp and that's authorizing

185
00:15:36,360 --> 00:15:39,300
it to access the spreadsheet itself.

186
00:15:39,990 --> 00:15:47,250
And then under that Vance tab, you can see the permissions that are going to be provided.

187
00:15:47,580 --> 00:15:52,620
Also, at any point, you can go to my account, Google dot com forward slash permissions to remove

188
00:15:52,620 --> 00:15:54,990
the permissions that you've added for any Web app.

189
00:15:55,350 --> 00:16:01,710
And that's under that link here where we've got the Google account to selecting allow to allow the authorization

190
00:16:02,340 --> 00:16:03,210
and then done.

191
00:16:03,300 --> 00:16:04,380
And let's go back.

192
00:16:04,380 --> 00:16:09,960
And now whenever we're sending the data, we're actually deposited into the spreadsheet.

193
00:16:10,710 --> 00:16:13,160
And that's all being done with the Google script.

194
00:16:14,070 --> 00:16:23,670
So let's minimize this and show you and just sometimes as good as well to test it out, just to make

195
00:16:23,670 --> 00:16:24,680
sure things are working.

196
00:16:25,020 --> 00:16:31,140
So now that we've got this content, we can separate it out because this is an object within the spreadsheets

197
00:16:31,770 --> 00:16:39,480
so we can separate out the content into different columns if we wanted to or if this is OK.

198
00:16:39,870 --> 00:16:42,120
We can also just track it directly.

199
00:16:45,050 --> 00:16:52,160
And as well, you can also take the data part and apply conditions on it before you send the actual

200
00:16:52,160 --> 00:16:52,610
email.

201
00:16:53,150 --> 00:16:59,270
So in this case, we're just going to keep it fairly simple and we'll check to see if the email we'll

202
00:16:59,270 --> 00:17:03,700
get the contents out and we've got that within a JSON object.

203
00:17:04,010 --> 00:17:09,170
So the email value is going to be chasten and that's contained within the email.

204
00:17:10,880 --> 00:17:18,500
There's the user and that's contained within the chase on the user value.

205
00:17:19,220 --> 00:17:28,040
And then the message is going to be contained within the JSON and that's contained within that Jason

206
00:17:28,040 --> 00:17:28,990
message object.

207
00:17:30,290 --> 00:17:34,280
So that's actually just going to separate out the values.

208
00:17:35,450 --> 00:17:40,860
And then we can also do this as an array now that we've separated the content.

209
00:17:41,540 --> 00:17:44,870
So this is just one way that we can get all of the post content.

210
00:17:47,790 --> 00:17:54,480
And each array within the earth, within the array, that's going to be a new line so we can just do

211
00:17:54,480 --> 00:18:02,410
email, user and message if we want to track that information back and redeploy it.

212
00:18:03,750 --> 00:18:07,140
So creating a new version, I think we're probably version five.

213
00:18:07,980 --> 00:18:13,200
And of course, for your real application, put actual real values into the names.

214
00:18:15,000 --> 00:18:16,390
So just click.

215
00:18:16,410 --> 00:18:25,740
And now we've got the email, we've got the name and we've got that content so we can delete the rows.

216
00:18:26,100 --> 00:18:34,160
We can actually insert one rule above and then use this as our kind of like a tracking email.

217
00:18:35,670 --> 00:18:45,240
So whenever any content comes in and let's reset it so we can track that information into the spreadsheet.

218
00:18:45,270 --> 00:18:47,230
So it's always going to drop it into the spreadsheet.

219
00:18:48,210 --> 00:18:53,060
And now last but of course, not least is to send the email.

220
00:18:53,760 --> 00:19:00,090
So also because this is JavaScript in the cloud, I can use the same function where I'm validating an

221
00:19:00,090 --> 00:19:07,500
email so I can just copy and paste the function over here and I can check to see if it's a valid email

222
00:19:07,500 --> 00:19:08,160
and so on.

223
00:19:10,070 --> 00:19:11,870
So we'll do our conditions.

224
00:19:14,500 --> 00:19:19,450
And right now it is true and we'll do our condition.

225
00:19:24,350 --> 00:19:33,440
And we'll validate the email address, so if it's not a valid email, so if it is a valid email, then

226
00:19:33,440 --> 00:19:34,520
we just keep it true.

227
00:19:34,940 --> 00:19:40,300
And if this comes back as false, so do negate it.

228
00:19:41,420 --> 00:19:48,440
And then here we can update the value of valid and said that to false.

229
00:19:49,470 --> 00:19:53,770
You can have any conditions on any of these, just as we did with JavaScript.

230
00:19:53,960 --> 00:20:00,830
So before you actually added we can have the condition and then if we want to append it to the spreadsheet

231
00:20:01,490 --> 00:20:04,490
here, we can append to the spreadsheet.

232
00:20:07,830 --> 00:20:13,170
And check to see if valid and if it is, then we run this code.

233
00:20:15,860 --> 00:20:19,160
And I'll also append Vallet here.

234
00:20:23,630 --> 00:20:25,730
And then this would just be the same thing.

235
00:20:25,760 --> 00:20:28,160
So this is whatever code you want to run.

236
00:20:28,580 --> 00:20:31,360
So actually append to rules for every submission.

237
00:20:32,720 --> 00:20:35,990
And this is just if you want to have conditions on it.

238
00:20:39,190 --> 00:20:49,870
So let's try that again and get our spreadsheet on screen, send the message so it's coming back true.

239
00:20:50,920 --> 00:20:56,080
And actually it's not going to let us submit if it's not a valid email, but if it did, then we could

240
00:20:56,080 --> 00:20:58,260
also catch it on the server side as well.

241
00:20:58,570 --> 00:20:59,820
So that's another option.

242
00:20:59,980 --> 00:21:04,750
And if you are sending an email, generally, it's good to make sure it is a valid email.

243
00:21:04,990 --> 00:21:11,800
If if it's not something that if you just want to get the messages no matter what, you can just simply

244
00:21:11,800 --> 00:21:13,810
send over the message information.

245
00:21:14,060 --> 00:21:15,670
So that's going to be the last part here.

246
00:21:15,820 --> 00:21:19,690
And actually it's really easy to send a message with a script.

247
00:21:20,020 --> 00:21:21,220
So it's created a function.

248
00:21:21,220 --> 00:21:26,500
I'll just call it Maler and this is going to take the user information.

249
00:21:26,500 --> 00:21:32,800
So email user and message and so email user and message.

250
00:21:36,360 --> 00:21:39,420
And we'll send it over, so if it is a valid.

251
00:21:42,210 --> 00:21:45,680
So if valid is OK, then we'll send a message.

252
00:21:51,730 --> 00:21:57,770
So it is all just type into the tracking the spreadsheet that we sent, the message.

253
00:21:58,660 --> 00:22:07,690
So within the mailer there's a function that sends mail and that's the mail app service within app script.

254
00:22:09,520 --> 00:22:13,840
And to send the email that's sent email.

255
00:22:14,500 --> 00:22:19,210
And then within the email, you've got a number of parameters that you can add in.

256
00:22:19,360 --> 00:22:22,090
So this is going to be within an object format.

257
00:22:22,660 --> 00:22:30,130
So to and where we're sending that email to and generally this will be my email address.

258
00:22:30,310 --> 00:22:32,260
So I want to receive all of the emails.

259
00:22:32,500 --> 00:22:35,890
And this is the email address that you want to send the email to.

260
00:22:38,210 --> 00:22:46,670
And there's also the subject, so whatever you want as the subject, I'm not sure I should be calling

261
00:22:47,180 --> 00:22:56,330
JavaScript object format from Web form and then for the body.

262
00:22:56,600 --> 00:22:59,120
So that's under HTML body.

263
00:23:01,040 --> 00:23:09,890
And with here, this is where you can construct the body contents that you want so you can do from name

264
00:23:10,640 --> 00:23:21,830
and then add in the Jason name or its design user and then construct whatever information you want,

265
00:23:22,490 --> 00:23:35,600
email and then add the chase on email and then the message and add the juice on the message.

266
00:23:36,710 --> 00:23:41,560
So that will send the email so you can customize this however you want.

267
00:23:42,140 --> 00:23:46,550
This is going to be an HTML, so you can just add in the line breaks.

268
00:23:49,580 --> 00:23:57,410
And there we go, and it's actually not passing in the Jason information, and we can just use the values

269
00:23:57,410 --> 00:23:58,610
that were actually passed and.

270
00:24:02,740 --> 00:24:14,260
So that was why it was throwing the air there and just save that, you can do the save and let's deploy

271
00:24:14,260 --> 00:24:15,310
it for the last time.

272
00:24:15,550 --> 00:24:17,830
So now we've got our final code.

273
00:24:19,930 --> 00:24:22,540
So that's the final version already.

274
00:24:22,820 --> 00:24:25,540
We need to authorize it to use the mail service.

275
00:24:25,870 --> 00:24:31,600
So, again, we cannot just authorize it on the email account that I've been using to create it.

276
00:24:31,960 --> 00:24:36,400
So under advanced and then go to contact Testor.

277
00:24:36,400 --> 00:24:38,830
So it just shows you the application name.

278
00:24:38,830 --> 00:24:46,990
So that's the same name as the deployment and the app script project name, and it tells you the permissions

279
00:24:46,990 --> 00:24:47,650
that were accepting.

280
00:24:47,670 --> 00:24:49,630
So there's the sheets, there's the email.

281
00:24:49,900 --> 00:24:51,010
So I'm OK with it.

282
00:24:51,010 --> 00:24:56,530
Hit allow and same end point URL.

283
00:24:57,040 --> 00:25:02,380
So go back into the JavaScript and within the Google email.

284
00:25:02,500 --> 00:25:07,010
Whenever you accept permissions, it'll give you a quick alert there about the permissions.

285
00:25:08,050 --> 00:25:11,890
So now let's refresh and click send.

286
00:25:13,470 --> 00:25:21,300
And it looks like we threw an error there, so let's do some quick troubleshooting and this is the best

287
00:25:21,300 --> 00:25:29,520
way to troubleshoot, just create a function to simulate the content that you're sending over and then

288
00:25:29,520 --> 00:25:32,040
you can select and run the test function.

289
00:25:33,900 --> 00:25:40,680
And it looks like the email address is not valid and not sure what happened there.

290
00:25:41,010 --> 00:25:44,320
So it didn't have an email address that it could send to.

291
00:25:45,080 --> 00:25:47,040
So let's run the tester one more time.

292
00:25:47,700 --> 00:25:49,080
So that looked like it sent.

293
00:25:49,090 --> 00:25:51,120
OK, could check your inbox.

294
00:25:51,120 --> 00:25:54,630
Just make sure that you were able to send the email.

295
00:25:55,800 --> 00:25:58,200
And it's actually I've got an S there at the end.

296
00:25:59,100 --> 00:26:05,510
So before we redeploy it, run the tester function just to make sure that it's running OK.

297
00:26:05,730 --> 00:26:07,080
And let's try that one more time.

298
00:26:08,520 --> 00:26:11,990
So that time it sent an email address without us.

299
00:26:12,570 --> 00:26:14,470
So there's our content being sent.

300
00:26:14,880 --> 00:26:20,870
So now we're ready to do another deployment and final and I'll just call it final final.

301
00:26:21,750 --> 00:26:27,270
So hopefully this will work properly and we don't have any issues.

302
00:26:27,570 --> 00:26:32,450
And then we can send the email from the content, from the form.

303
00:26:32,580 --> 00:26:37,380
So it's clear that and hit send and go to our email.

304
00:26:38,880 --> 00:26:47,460
And now we've got the content coming from the localhost and that's being sent to our email address so

305
00:26:47,460 --> 00:26:49,690
that we've got some content that's been filled out there.

306
00:26:49,980 --> 00:26:59,220
In addition, we're also adding it to the spreadsheet so you can either copy the Google app script code

307
00:26:59,580 --> 00:27:02,790
that I was using or create your own version.

308
00:27:04,020 --> 00:27:08,580
And you're going to and just make sure that you have the endpoint set up and you could be ready to move

309
00:27:08,580 --> 00:27:11,100
on to the last lesson where we're going to finalize the application.

310
00:27:13,390 --> 00:27:20,800
Thanks for this lesson, our log into your Google account, create the new doc, access the script editor

311
00:27:20,800 --> 00:27:27,490
from within the sheet so that can be done under the tools and then go down to the script editor that

312
00:27:27,490 --> 00:27:32,770
will open up your Google app, script ID, online ID, and from there you can start writing scripts.

313
00:27:32,950 --> 00:27:39,370
So create the do post function and that's the default function for the post method to the webapp end

314
00:27:39,370 --> 00:27:43,390
point and then get the contents that are being passed in.

315
00:27:43,390 --> 00:27:54,010
So the post data using the E post data get content or contents, object property and pass that back

316
00:27:54,010 --> 00:28:01,510
into a usable JavaScript object that then you can deconstruct and use within the Google script.

317
00:28:01,840 --> 00:28:10,330
You can append a roll to the spreadsheet by using the add roll method and using the spreadsheet app

318
00:28:10,330 --> 00:28:19,090
service and also send an email using mail app services using the send email function.

319
00:28:20,730 --> 00:28:27,960
Available within the mail app and send the post data over to your email address.

320
00:28:33,110 --> 00:28:39,860
And then finalize, deploy at your end point and use that endpoint within your local machine when you're

321
00:28:39,860 --> 00:28:46,220
doing testing to make sure that you're able to send data over to the endpoint and also that you've got

322
00:28:46,220 --> 00:28:49,580
the emails that are coming in properly to your account.
