1
00:00:00,900 --> 00:00:08,370
So our next major topic is how do we send email and what I want to do here is whenever someone makes

2
00:00:08,370 --> 00:00:11,520
a reservation on our site, I want to send two email messages.

3
00:00:11,820 --> 00:00:16,800
I want to send one to the property owner just to alert him or her that there is a new reservation.

4
00:00:17,100 --> 00:00:21,620
And I want to send a confirmation email to the person who made the reservation in the first place.

5
00:00:22,170 --> 00:00:24,120
And this is not terribly difficult.

6
00:00:24,300 --> 00:00:29,040
So what I'm going to do is look around and I already have done I've already done so look around and

7
00:00:29,040 --> 00:00:35,070
find a mail package that I can just import into my project and use one where the work is already done.

8
00:00:35,370 --> 00:00:38,190
And it's maintained on a fairly regular basis.

9
00:00:38,190 --> 00:00:43,380
And I found this one, which is called Go Simple Mail, which sounds ideal for my purposes.

10
00:00:44,100 --> 00:00:51,060
And if you look at the district description, it's it will talk to an SMTP server, which SMTP stands

11
00:00:51,060 --> 00:00:52,890
for simple mail transfer protocol.

12
00:00:53,340 --> 00:00:57,650
It actually does everything we want and it's pretty easy to install and pretty easy to use.

13
00:00:57,900 --> 00:01:00,990
So let's copy the part here on this page.

14
00:01:00,990 --> 00:01:05,100
And I will and this is the URL, but I'll post a link to this to the course resources.

15
00:01:05,550 --> 00:01:09,270
Let's copy this and install it into our project.

16
00:01:09,300 --> 00:01:11,840
So back I go to buy Idy.

17
00:01:11,850 --> 00:01:15,240
I open a terminal window, make sure I'm at the root level of my project.

18
00:01:15,240 --> 00:01:21,300
I am and I paste that command in and it will go and get it and install it and that modifies our go mod

19
00:01:21,300 --> 00:01:23,120
file and we now have it available to us.

20
00:01:23,970 --> 00:01:29,940
So in order to send email we're going to need to know certain things at a bare minimum.

21
00:01:29,940 --> 00:01:35,900
We're going to have to know the to address the from address the subject and the content.

22
00:01:36,300 --> 00:01:43,530
So what I'm going to do now is go and create a struct, a type that will hold that kind of contact content.

23
00:01:43,530 --> 00:01:48,210
So I'm going to go to my model's directory and I'll put it in models because this is a model and at

24
00:01:48,210 --> 00:01:53,670
the very bottom of it, I'll create a new type type and I'll call it mail data, which is a good name.

25
00:01:53,670 --> 00:01:55,740
I think it's a struct.

26
00:01:55,740 --> 00:01:58,350
And it will have four members too, which is a string.

27
00:01:58,350 --> 00:02:02,550
That's the email address that I'm sending to from which is a string.

28
00:02:02,830 --> 00:02:09,570
Again, the email address that I'm sending from the subject of the email, which will be a string and

29
00:02:09,570 --> 00:02:10,950
the content of the email.

30
00:02:10,950 --> 00:02:12,270
And I'm not going to make this a string.

31
00:02:12,270 --> 00:02:18,000
I could, but I want might want to put formatting in that email and that means I'm going to be sending

32
00:02:18,000 --> 00:02:18,720
HTML.

33
00:02:18,930 --> 00:02:25,380
So instead of making it a string, I'll make it template HTML, which is a built in type that allows

34
00:02:25,380 --> 00:02:30,630
us to actually have formatting in the content that we're going to be sending out via email.

35
00:02:30,660 --> 00:02:32,130
And I'll put a comment on this.

36
00:02:32,580 --> 00:02:44,220
Mail data holds an email message, so I've now imported the package I want to use to send email.

37
00:02:44,760 --> 00:02:53,360
And I have also set up a a model to hold the email messages that I'll be sending.

38
00:02:53,370 --> 00:02:56,660
Now we need to get to the nitty gritty of how to send email.

39
00:02:57,090 --> 00:03:01,140
So first thing I'm going to tell you is that I'm not going to and I could do this.

40
00:03:01,140 --> 00:03:07,650
I could just create a helper function and that go construct my mail message wherever I want to send

41
00:03:07,650 --> 00:03:09,960
it and then call that function and have it send it.

42
00:03:10,170 --> 00:03:12,480
But I'm going to make it a little more complicated.

43
00:03:12,550 --> 00:03:17,570
I'm going to do it because you need to have a little more experience working with channels in go.

44
00:03:17,880 --> 00:03:23,790
And this is a perfect opportunity to use a channel to send email and to write the code necessary to

45
00:03:23,790 --> 00:03:29,690
have a worker that listens for data, center that channel and perform some action when it receives it.

46
00:03:30,120 --> 00:03:34,380
So I'm going to, first of all, go to my main function in command web.

47
00:03:34,380 --> 00:03:36,090
I'm going to open Mango.

48
00:03:37,950 --> 00:03:45,030
And in here I am going to think about what I'm going to do, what I want to do in this this this code,

49
00:03:45,180 --> 00:03:51,150
either in my main function or am I run function or both, as I want to create a channel that will be

50
00:03:51,150 --> 00:03:54,270
available to all parts of my application at any time.

51
00:03:54,570 --> 00:03:56,400
And that channel serves one purpose.

52
00:03:56,610 --> 00:04:04,530
It's going to listen for a data type of models, dot mailed mail data, that one we just created.

53
00:04:05,070 --> 00:04:06,450
So how do you create a channel?

54
00:04:06,480 --> 00:04:11,820
Well, we already looked at that a long time ago at the very early part of this this course.

55
00:04:12,690 --> 00:04:14,250
So we know how to create a channel.

56
00:04:14,610 --> 00:04:16,740
But a question is where do I put it?

57
00:04:16,890 --> 00:04:21,630
I can create a channel in my main function or I can create a channel in my run function, but I want

58
00:04:21,630 --> 00:04:23,930
it to be available to my entire application.

59
00:04:24,510 --> 00:04:28,250
Well, why not put it in our config, in our app config?

60
00:04:28,500 --> 00:04:35,160
So what I'm going to do is open up config, go and add a new member to this struct, which I will call

61
00:04:35,370 --> 00:04:42,670
male channel, and it's going to be a channel of type models, dot male data.

62
00:04:44,160 --> 00:04:50,280
So now once I create the channel and populate in my app config, it will be available to every part

63
00:04:50,280 --> 00:04:56,700
of my application that has access to the config, which is in our case, pretty much every part of our

64
00:04:56,700 --> 00:04:57,290
application.

65
00:04:57,300 --> 00:04:58,070
So I've created that.

66
00:04:58,560 --> 00:04:59,860
So let's go back to our main Dr..

67
00:05:00,710 --> 00:05:05,300
And let's create this channel and I'll do it down in the room function and I'll do it right after my

68
00:05:05,300 --> 00:05:10,940
gob register bid, so I'll create a new variable called Milchan and that will be assigned the value

69
00:05:10,940 --> 00:05:14,630
of make channe models male data.

70
00:05:15,590 --> 00:05:20,810
So now I have this channel and as I told you really early on in the course, we're going to need to

71
00:05:21,050 --> 00:05:25,870
put a defer close on this channel because you don't want to leave channels to open all the time.

72
00:05:26,750 --> 00:05:31,340
But as was the case with something else in this, and I can't remember what our database connections,

73
00:05:31,340 --> 00:05:38,300
if I put my designer clothes here, it's actually going to close it as soon as this run function is

74
00:05:38,300 --> 00:05:39,140
done executing.

75
00:05:39,140 --> 00:05:43,000
And this only runs once at the very first time we start our application.

76
00:05:43,550 --> 00:05:47,120
It's called right up here and then it closes.

77
00:05:47,210 --> 00:05:48,320
So I don't want to close it here.

78
00:05:48,350 --> 00:05:53,240
Instead, I will populate my app Dot Milchan with Milchan.

79
00:05:53,540 --> 00:05:55,490
It's equal to Milchan.

80
00:05:56,210 --> 00:06:03,050
And then up here I will just before I put starting application in my main function, I will put a defer

81
00:06:04,070 --> 00:06:08,830
defer close match app Milchan.

82
00:06:09,980 --> 00:06:13,120
So now I have it closed properly and this is really not enough.

83
00:06:13,130 --> 00:06:17,600
So far I've created the place to hold email messages in models, dot mail data.

84
00:06:18,140 --> 00:06:24,650
I've created a channel to send messages through and I've closed the channel, which will happen when

85
00:06:24,650 --> 00:06:25,790
the application stops.

86
00:06:26,030 --> 00:06:28,250
But I haven't actually sent any messages.

87
00:06:28,250 --> 00:06:30,350
I have no means of sending a message.

88
00:06:30,950 --> 00:06:33,500
So what am I going to do with this at Baleka?

89
00:06:33,650 --> 00:06:36,320
Well, let's think about what we might want to do.

90
00:06:36,680 --> 00:06:42,140
What I really want to do is have some part of my application that listens for that channel.

91
00:06:42,440 --> 00:06:46,840
And it says, when I received some information from this channel, here's what I do with it.

92
00:06:47,210 --> 00:06:50,690
So I need someplace to actually listen for this channel.

93
00:06:51,110 --> 00:06:57,020
So let's do that, because in the example we did way back when we just created a channel in the main

94
00:06:57,020 --> 00:07:03,530
function, sent something through a function that was beside the main function and then close the channel.

95
00:07:03,530 --> 00:07:08,360
It was a one shot program that started did what it had to do and then stopped.

96
00:07:08,360 --> 00:07:14,270
And in this case, we have an application that starts and it keeps running until we physically go and

97
00:07:14,270 --> 00:07:15,260
stop the server.

98
00:07:15,980 --> 00:07:17,820
So we need something that's going to listen to this.

99
00:07:17,840 --> 00:07:22,760
So what I'm going to do is in my Web folder, I'm going to create a new file, a new go file, and it's

100
00:07:22,760 --> 00:07:28,910
going to be called Send Dash Email Dutko and I will add this to my repository.

101
00:07:29,570 --> 00:07:31,220
So it's part of a package main.

102
00:07:31,910 --> 00:07:33,250
And what do I want to do in this?

103
00:07:33,260 --> 00:07:36,410
Well, I'm going to create a function and the function is going to be called func.

104
00:07:36,560 --> 00:07:42,680
Listen for mail, which is a nice descriptive title, it takes no parameters and it returns nothing.

105
00:07:43,160 --> 00:07:47,290
And inside of this, what I want to do is to listen to that channel.

106
00:07:47,690 --> 00:07:53,390
Well, as you may recall, the way that we get information from a channel is just to declare a variable

107
00:07:53,390 --> 00:07:59,390
like M for message and make that as equal to whatever I get from the channel I want to listen to, which

108
00:07:59,390 --> 00:08:01,060
in this case is apt e-mail chat.

109
00:08:01,760 --> 00:08:07,130
Now, I could do that and then use this message to create and send an email message.

110
00:08:08,210 --> 00:08:15,020
But it's really not helpful because again, this function needs to be called every single time I want

111
00:08:15,020 --> 00:08:20,910
to send a message and that defeats the entire purposes or purpose of channels in the first place.

112
00:08:21,350 --> 00:08:26,840
So what I'm going to do is just get rid of this entirely and I'm going to create something that runs

113
00:08:26,840 --> 00:08:32,120
indefinitely and fires things off in the background to to happen asynchronously.

114
00:08:32,120 --> 00:08:37,520
So every time I get a message I want it to send, but I don't want the application to stop running Wallace

115
00:08:37,520 --> 00:08:38,320
sending that email.

116
00:08:38,690 --> 00:08:45,470
So if I was to write this procedurally and just send constructive message, connect to the mail server,

117
00:08:45,470 --> 00:08:50,210
send the message and keep going, there could be a delay and that delay could be three, four or five,

118
00:08:50,210 --> 00:08:53,600
maybe ten seconds, because sometimes it's slow to send email.

119
00:08:53,610 --> 00:08:56,270
So what I want to do instead is have that happen in the background.

120
00:08:56,420 --> 00:08:57,920
And here's how I'm going to make this work.

121
00:08:58,280 --> 00:09:02,960
I'm going to fire off in the background, start a go routine by using that command go.

122
00:09:03,320 --> 00:09:08,030
And I'm going to fire an unnamed function or an anonymous function.

123
00:09:08,480 --> 00:09:12,440
So to do that, I just say func and then open and close parentheses.

124
00:09:12,440 --> 00:09:14,090
And I'm not putting any parameters in there.

125
00:09:14,450 --> 00:09:18,080
I have the standard body curly braces.

126
00:09:18,320 --> 00:09:22,910
And then on the closing curly brace, I'm just going to put two more parentheses.

127
00:09:23,150 --> 00:09:26,060
And now I have a function that will execute in the background.

128
00:09:26,450 --> 00:09:31,240
And what I want this to do is to listen all the time for incoming data.

129
00:09:31,700 --> 00:09:36,110
So what I'm going to listen for, I'll just use a force, a for loop with no conditions.

130
00:09:36,530 --> 00:09:38,870
And I'm going to listen to that channel.

131
00:09:38,870 --> 00:09:44,360
Now, you would think I could do this message, which will be a variable I declare is equal to whatever

132
00:09:44,360 --> 00:09:46,880
you get from my laptop.

133
00:09:46,880 --> 00:09:47,420
Milchan.

134
00:09:50,470 --> 00:09:52,090
And then I can send my message.

135
00:09:52,120 --> 00:09:55,980
So let's see if this works, let's go construct a message.

136
00:09:56,440 --> 00:10:00,580
So what I'm going to do now is I don't want to put this sending part right in this Falu because that

137
00:10:00,580 --> 00:10:01,630
becomes a bit awkward.

138
00:10:01,870 --> 00:10:09,520
I'll just get another function called Funk Send Message and now will actually pass some parameters to

139
00:10:09,520 --> 00:10:09,820
this.

140
00:10:10,360 --> 00:10:16,030
And in this case, this will receive a parameter which I'm going to call em, which is of type models,

141
00:10:16,210 --> 00:10:16,890
e-mail data.

142
00:10:18,520 --> 00:10:19,860
This doesn't return anything.

143
00:10:19,900 --> 00:10:23,080
This just sends email and here's how you actually send email.

144
00:10:23,560 --> 00:10:26,590
So we imported that package a little while ago and now we're going to use it.

145
00:10:26,590 --> 00:10:33,070
And the first step is to tell our mail package, the one that we just imported, go simple mail what

146
00:10:33,070 --> 00:10:33,940
our server is.

147
00:10:33,940 --> 00:10:40,870
So I'll create a variable called server that's going to be assigned the value of mail dot new SMTP client.

148
00:10:41,930 --> 00:10:47,840
OK, and this server is going to have some information associated with it, so where is your e-mail

149
00:10:47,840 --> 00:10:48,230
server?

150
00:10:48,260 --> 00:10:54,700
Well, in our case, it's going to be server dot host is equal to and we're just going to use localhost.

151
00:10:54,740 --> 00:10:58,190
We're going to install a dummy mail server on our machines in a little while.

152
00:10:58,190 --> 00:11:03,200
But we can do this part first and it's going to listen on a particular part, just like a Web server

153
00:11:03,200 --> 00:11:07,400
listens on Port 80 or 443 mail servers.

154
00:11:07,400 --> 00:11:08,600
Also listen on ports.

155
00:11:08,600 --> 00:11:14,540
So this one has a port and the port for our dummy server that we're going to install will be 10, 25.

156
00:11:15,000 --> 00:11:21,650
OK, real mail servers, USB port twenty five, Port 587 or 465 for the most case.

157
00:11:21,950 --> 00:11:26,480
But right now we're going to be using a dummy e-mail server and I'll set some other parameters on this

158
00:11:26,480 --> 00:11:26,920
as well.

159
00:11:26,930 --> 00:11:31,700
I don't want to keep the connection to the e-mail server active all the time.

160
00:11:31,700 --> 00:11:32,930
So I'll say make that false.

161
00:11:32,930 --> 00:11:38,210
Only make a connection when I tell you to send email and I'll give it some sensible timeouts.

162
00:11:38,210 --> 00:11:41,450
So server dot connect timeout.

163
00:11:41,630 --> 00:11:44,750
I'll make that 10 seconds, 10 times time dot second.

164
00:11:46,220 --> 00:11:51,710
So if you can't connect within 10 seconds, just give up and server dot send time out.

165
00:11:51,720 --> 00:11:53,350
I'll make that 10 seconds as well.

166
00:11:55,960 --> 00:11:59,170
Now, that's the basic information to connect to a male server.

167
00:11:59,230 --> 00:12:01,600
There are other things that you will need in production.

168
00:12:01,630 --> 00:12:09,070
You will need, for example, server username and server password and server dot encryption.

169
00:12:09,460 --> 00:12:11,170
But we don't have that for a dummy server.

170
00:12:11,170 --> 00:12:13,270
And it doesn't matter for the purposes of this course.

171
00:12:13,270 --> 00:12:17,470
When you go to connect to a live server, you'll have to specify those things, but you'll have to find

172
00:12:17,470 --> 00:12:18,440
out what they are first.

173
00:12:19,390 --> 00:12:24,640
So for our purposes, this will give us a means of connecting to a local mail server, which I happen

174
00:12:24,640 --> 00:12:26,100
to have installed and running already.

175
00:12:26,140 --> 00:12:27,310
You don't don't worry about it.

176
00:12:27,310 --> 00:12:27,840
You'll get there.

177
00:12:28,330 --> 00:12:31,240
Now we need a client just like we have a server.

178
00:12:31,240 --> 00:12:32,050
We have to have a client.

179
00:12:32,050 --> 00:12:37,600
So here client and error are assigned the value of server iConnect.

180
00:12:40,830 --> 00:12:45,070
And that since that throws an error, we have to look for that if there is not equal to nil.

181
00:12:45,690 --> 00:12:51,410
I'll just print the error log print line error, OK?

182
00:12:53,460 --> 00:13:00,900
And now we actually need to construct our email message in a format that our client understands.

183
00:13:00,900 --> 00:13:04,290
And we do that using this variable M that we've got right up here.

184
00:13:04,290 --> 00:13:07,550
We already have our model mailed it and that has everything we need.

185
00:13:08,370 --> 00:13:16,400
So I will say email is assigned the value of mail new message which creates a new empty message.

186
00:13:17,400 --> 00:13:21,390
This creates a struct and the struct is a pointer to email.

187
00:13:21,390 --> 00:13:27,540
And we get that from our mail package, which I automatically import it up here, or it automatically

188
00:13:27,540 --> 00:13:29,420
imported itself and called itself mail.

189
00:13:30,210 --> 00:13:34,650
So we have mailed a new message and that's assigned to a variable email.

190
00:13:34,710 --> 00:13:38,190
And now we just set the frame to in subject email dot from.

191
00:13:40,470 --> 00:13:52,230
Not get from e-mail dot set from is set to emerg from and then I can use a dot and keep setting configurations

192
00:13:52,230 --> 00:13:58,740
here, I'll add a two address and my two will be morto and all that.

193
00:13:58,740 --> 00:14:03,870
A subject set subject is equal to Emerg subject.

194
00:14:05,570 --> 00:14:08,510
So this actually creates an empty e-mail message.

195
00:14:08,690 --> 00:14:16,670
This next line sets the from to an email address, sets the two to an email address and sets the subject

196
00:14:16,670 --> 00:14:17,400
to a subject.

197
00:14:17,750 --> 00:14:19,820
Now we just need to put the content of our body in there.

198
00:14:20,240 --> 00:14:24,410
So email dot set body is the next one.

199
00:14:24,470 --> 00:14:29,240
Now, I put this on a separate line because for right now, I don't want to manually construct an email

200
00:14:29,240 --> 00:14:29,570
message.

201
00:14:29,570 --> 00:14:31,220
I just want to make sure this works OK.

202
00:14:31,730 --> 00:14:33,830
So this requires two parameters.

203
00:14:33,860 --> 00:14:35,030
What your content type.

204
00:14:35,030 --> 00:14:38,380
And we actually have some predefined constants in this mail package.

205
00:14:38,660 --> 00:14:40,310
I'm going to set mine to HTML.

206
00:14:40,490 --> 00:14:42,620
So mail dot text HTML.

207
00:14:43,370 --> 00:14:49,280
That's the type of the content and I will put some content in here in the form of image of HTML.

208
00:14:49,730 --> 00:14:55,690
Hello, comma strong world and my strong tag exclamation mark.

209
00:14:56,510 --> 00:14:57,310
And now I need this.

210
00:14:57,380 --> 00:15:01,100
I'm finally at the point where I can send an email message and you do it like this.

211
00:15:01,130 --> 00:15:08,660
Error is equal to email dot send and you pass it to the client that you've just set up and that client

212
00:15:09,260 --> 00:15:11,480
has everything it needs to know.

213
00:15:11,810 --> 00:15:18,830
It has the server information, it has the client information and it has the email body or email message

214
00:15:18,860 --> 00:15:19,580
actually in there.

215
00:15:19,610 --> 00:15:23,630
So since I'm sending that with an email or sending that and getting an error, I should check for it.

216
00:15:24,110 --> 00:15:28,880
If error is not equal to nil, then I will log print line error.

217
00:15:29,630 --> 00:15:34,430
Otherwise, in this case, I'm actually going to say logged logged print line.

218
00:15:35,360 --> 00:15:36,050
Email set.

219
00:15:41,010 --> 00:15:49,170
OK, so there it is, I have my function already to send email, and it seems as though I could just

220
00:15:49,170 --> 00:15:55,710
listen to this channel indefinitely because it never goes out of this for loop and send a message when

221
00:15:55,710 --> 00:16:01,440
I get one so I can just say send a message, the function I just built and pass it MSG, which is my

222
00:16:01,440 --> 00:16:01,890
message.

223
00:16:02,520 --> 00:16:03,780
Shouldn't that work?

224
00:16:03,790 --> 00:16:05,310
It would seem that it should.

225
00:16:05,820 --> 00:16:09,690
But this listen for mail function is never actually called.

226
00:16:09,690 --> 00:16:12,690
So let's go back to our main function and set that up.

227
00:16:14,100 --> 00:16:17,010
And I would do that obviously somewhere up here.

228
00:16:17,010 --> 00:16:24,570
I could say right after my designer clothes, after I set my DHAFIR Command to close the email channel.

229
00:16:24,900 --> 00:16:30,840
When I'm done with the program, I can just say start that listening for email messages by running the

230
00:16:30,840 --> 00:16:31,350
command.

231
00:16:31,740 --> 00:16:34,350
Listen, for now, let's see if that works.

232
00:16:34,470 --> 00:16:40,200
So I'm going to open my terminal window, clear the screen and run my program.

233
00:16:42,600 --> 00:16:43,500
I'm in the right direction.

234
00:16:43,530 --> 00:16:45,860
I am so let's just say run and see what happens.

235
00:16:50,970 --> 00:16:52,990
Seem to work, seem to be listening.

236
00:16:53,010 --> 00:16:55,020
OK, let's stop that again.

237
00:16:57,550 --> 00:17:04,180
I've got my app channel all set up, let's actually try sending an email message, so I'll do it right

238
00:17:04,180 --> 00:17:05,450
after listening for email.

239
00:17:05,500 --> 00:17:08,520
I'm going to put it right on my main function just to make sure that things work.

240
00:17:08,530 --> 00:17:14,260
So the first thing I need is a message, and that will be of type models, dot mail data.

241
00:17:15,400 --> 00:17:19,590
And I will choose Phil all fields just to make it easier for for myself.

242
00:17:19,600 --> 00:17:28,630
So to John at Doe Dossie from me at here, Dotcom, those have to be in the form of email addresses,

243
00:17:28,900 --> 00:17:35,830
subject some subject and content and doesn't matter what content it is because I'm manually putting

244
00:17:35,830 --> 00:17:37,840
that in myself.

245
00:17:38,080 --> 00:17:46,090
So if I want to send to that channel now all I have to do is say app dot mail channel and pass it the

246
00:17:46,090 --> 00:17:46,540
message.

247
00:17:47,950 --> 00:17:55,570
So let's stop this and see what happens now on my now on my local computer, I actually have this e-mail

248
00:17:55,570 --> 00:17:58,350
server you're going to be installing shortly already installed.

249
00:17:58,750 --> 00:18:03,820
So let me start up that mail server and it's called Mail Hug, an unfortunate name, but a great dumb

250
00:18:03,820 --> 00:18:04,560
email server.

251
00:18:04,990 --> 00:18:08,410
And this is now listening for or it's listening all the time.

252
00:18:08,410 --> 00:18:10,060
I just happened to open the Web interface to it.

253
00:18:10,240 --> 00:18:12,370
It's listening for emails.

254
00:18:12,880 --> 00:18:17,440
So let me go back to my I.D. and run this and see what happens.

255
00:18:18,520 --> 00:18:20,050
So I will clear the screen.

256
00:18:22,190 --> 00:18:22,700
And runit.

257
00:18:26,080 --> 00:18:28,190
And off it goes and it says email sent.

258
00:18:28,210 --> 00:18:33,970
So let's go back and have a look in this mail client and there is the email from me out here, NORCOM

259
00:18:34,120 --> 00:18:36,220
to John at Doe Dossie.

260
00:18:36,490 --> 00:18:37,360
And I can view that.

261
00:18:37,360 --> 00:18:39,160
And there it is.

262
00:18:39,400 --> 00:18:41,780
And there seems to be working really well.

263
00:18:42,400 --> 00:18:48,130
So what this looks like I can do at this point is I can actually just anytime I want to send an email

264
00:18:48,130 --> 00:18:54,070
message, construct it using this format, populate the content with the actual content that I want,

265
00:18:54,070 --> 00:18:59,250
of course, and then send it to that channel and that will send email in the background.

266
00:18:59,770 --> 00:19:05,080
So the last thing I have to do to make this actually functional is to go back to send Dasch mail ago

267
00:19:05,740 --> 00:19:06,880
and get rid of this part.

268
00:19:07,810 --> 00:19:14,610
Don't hardcourt that instead use more content and that should work.

269
00:19:14,620 --> 00:19:17,590
And this has to be in the form of type string.

270
00:19:17,590 --> 00:19:19,500
So it's actually template HTML.

271
00:19:20,050 --> 00:19:25,450
Well, I can actually cast that back to a string, but it might be simpler just to go to our config

272
00:19:25,660 --> 00:19:29,050
and say, no, this, this not our config, our models.

273
00:19:29,050 --> 00:19:34,660
Dudko and change the structure from template html back to string.

274
00:19:35,110 --> 00:19:38,650
I thought we had to cast it to put it in template html format.

275
00:19:38,660 --> 00:19:41,450
Turns out we don't, so that's even simpler.

276
00:19:41,860 --> 00:19:44,530
So now I have everything I need to be able to send email.

277
00:19:44,530 --> 00:19:48,190
So let's comment this stuff out from here.

278
00:19:50,880 --> 00:19:54,840
Because we're not going to be wanting to send an email every time we start the program and let's just

279
00:19:54,840 --> 00:20:02,370
add a message right here, format, print line and I'll save starting mail listener.

280
00:20:04,960 --> 00:20:07,300
So when we started it up, now we should get that message.

281
00:20:07,330 --> 00:20:12,570
Let me stop this, clear it and make sure it all compiles and see if we get that message.

282
00:20:14,380 --> 00:20:19,960
And we do everything is working perfect, so in the next lecture, we'll actually look at sending emails

283
00:20:19,960 --> 00:20:23,380
around to our guest and to our property owner.
