1
00:00:02,070 --> 00:00:06,810
So now we want to look at how we can make our emails a little prettier, and I'm not going to put a

2
00:00:06,810 --> 00:00:10,550
great deal of effort into actually making it pretty because I'll leave that up to you.

3
00:00:10,560 --> 00:00:12,640
But I'll show you how you can do it quite easily.

4
00:00:13,290 --> 00:00:20,160
You may recall that for our public facing website, we're using the bootstrap framework to format things,

5
00:00:20,160 --> 00:00:22,410
and that makes things ever so easy.

6
00:00:22,740 --> 00:00:26,730
But there are more found more frameworks out there based on cascading style sheets.

7
00:00:26,940 --> 00:00:30,660
And one of them is called Foundation, which is produced by the ZRP Foundation.

8
00:00:30,990 --> 00:00:37,010
And the site you're looking at right now is is getting foundations, emails, dot, HTML.

9
00:00:37,770 --> 00:00:45,330
And this is a subset of a sixth framework called Foundation, which is intended to be used exclusively

10
00:00:45,330 --> 00:00:46,260
for email.

11
00:00:46,740 --> 00:00:49,350
So go there and then click get started.

12
00:00:50,100 --> 00:00:54,840
And then we want to download this and I'm going to download I'm not going to use the SAS version because

13
00:00:54,840 --> 00:01:00,570
I don't want to get into actually writing SACE right now, which is a way of managing access.

14
00:01:00,810 --> 00:01:04,020
Instead, just download the access version, so download the starter kit.

15
00:01:04,500 --> 00:01:06,590
And when you do that, you'll get a zip file.

16
00:01:06,600 --> 00:01:11,100
And I'm going to show you that I have the zip file already and I've expanded it.

17
00:01:11,130 --> 00:01:14,430
So get it and extract it, then open it up.

18
00:01:15,060 --> 00:01:20,580
And inside of that, you'll see in this year's success folder the actual access that's used.

19
00:01:20,880 --> 00:01:23,160
But what I want to look at right now are the templates.

20
00:01:23,160 --> 00:01:24,810
And I'm going to look at some of these.

21
00:01:24,810 --> 00:01:25,470
Just preview them.

22
00:01:25,950 --> 00:01:31,590
There's a preview of the template that's called Basic, which looks like it's ideal for my purposes.

23
00:01:31,920 --> 00:01:32,580
But there are others.

24
00:01:32,580 --> 00:01:33,660
You can go through the whole list.

25
00:01:33,670 --> 00:01:36,020
There's the responsive emails, which is very nice.

26
00:01:36,480 --> 00:01:38,100
There's Elijah Bailey.

27
00:01:38,100 --> 00:01:39,060
There's all of these things.

28
00:01:39,070 --> 00:01:42,860
So the one I want to work with is the right here.

29
00:01:42,870 --> 00:01:44,670
Let's get back up and find the right one again.

30
00:01:45,090 --> 00:01:46,530
It's not this one.

31
00:01:46,740 --> 00:01:48,800
It is this one dripped HTML.

32
00:01:48,810 --> 00:01:53,150
That looks like a nice format for me to use in this course.

33
00:01:53,430 --> 00:02:01,260
So what I'm going to do is open up dripped on HTML in my favorite text editor, go away in my favorite

34
00:02:01,260 --> 00:02:03,750
text editor, so I'll put it up in sublime text.

35
00:02:03,750 --> 00:02:04,980
You can use any text editor.

36
00:02:04,980 --> 00:02:07,470
You want to try that again.

37
00:02:08,250 --> 00:02:08,690
Drip.

38
00:02:09,030 --> 00:02:09,550
There it is.

39
00:02:10,380 --> 00:02:15,150
So this is just HTML with a bunch of inline access.

40
00:02:15,150 --> 00:02:18,630
So this is just the way we've been doing earlier in the course.

41
00:02:19,170 --> 00:02:25,830
This is just an HTML file and it has a whole bunch of success which is suitable for making emails and

42
00:02:25,830 --> 00:02:26,880
making responsive emails.

43
00:02:27,270 --> 00:02:33,480
So I'm going to copy this whole thing and then I'm going to go back to my editor, my goaland in my

44
00:02:33,480 --> 00:02:40,170
case, and I might create a new folder at the root level of my project and I will call that directory

45
00:02:40,800 --> 00:02:42,960
email templates.

46
00:02:45,010 --> 00:02:53,710
And inside of that, I'll create a new file, which I will call basic HTML, and I'm going to paste

47
00:02:53,710 --> 00:02:58,360
the contents of that HTML file I just copied into this file.

48
00:02:58,360 --> 00:03:01,600
And this will be a template that we can use to send email.

49
00:03:01,960 --> 00:03:04,810
So what I need to do is to get rid of the things that I don't want.

50
00:03:04,840 --> 00:03:06,520
So let's go back and preview that again.

51
00:03:08,440 --> 00:03:11,020
I don't want this responsive email heading like this.

52
00:03:11,230 --> 00:03:17,350
Maybe I want to have the title there, but I definitely don't want this 15 sections, 567 minutes.

53
00:03:17,350 --> 00:03:18,160
I don't want this.

54
00:03:18,160 --> 00:03:19,000
I don't want the button.

55
00:03:19,000 --> 00:03:22,200
And I'll fix this to what I want it to be at the bottom of my message.

56
00:03:22,570 --> 00:03:26,530
So we need to fix this this template, get rid of the things that we don't want.

57
00:03:27,430 --> 00:03:32,440
So what I'm going to do here is scroll all the way down past the access and there's a lot of it.

58
00:03:32,440 --> 00:03:36,590
But don't worry about that and get down to the part that I actually don't want.

59
00:03:37,030 --> 00:03:40,240
So somewhere here we have.

60
00:03:41,660 --> 00:03:42,200
There it is.

61
00:03:42,230 --> 00:03:49,610
I don't want this part, the 15 sections and 567 minutes, I'm going to delete that and I'll just put

62
00:03:49,610 --> 00:03:53,630
the name of my bed and breakfast here.

63
00:03:53,780 --> 00:03:56,220
So the name of my bed and breakfast, I can't remember what it is.

64
00:03:56,240 --> 00:03:57,130
Let's go find out.

65
00:03:57,740 --> 00:03:58,730
Localhost.

66
00:04:00,990 --> 00:04:02,550
Localhost 80.

67
00:04:03,030 --> 00:04:09,090
Hopefully that's running and it is and I call this Fort Smith bed and breakfast, so I'll just put Fort

68
00:04:09,090 --> 00:04:17,490
Smith in there instead of Fort Smith, and then I'm going to come down here and find this section.

69
00:04:17,500 --> 00:04:19,130
I don't want this in here.

70
00:04:19,140 --> 00:04:25,050
Instead, what I want in this is going to be some content and I need a placeholder.

71
00:04:25,050 --> 00:04:29,340
What I'm going to do is use this as a template and then I'm going to load the template before I send

72
00:04:29,340 --> 00:04:34,770
an email and I'll substitute something that I put in here that I know is never going to appear in an

73
00:04:34,770 --> 00:04:38,730
actual email message, some kind of text that I can search and replace on.

74
00:04:38,940 --> 00:04:45,600
So I'll use square brackets and a percent sign and I will call it body.

75
00:04:47,350 --> 00:04:52,540
There and I can have as many of those placeholders as I want, but that's what I'm going to do right

76
00:04:52,540 --> 00:04:58,420
now, is just use one so square bracket, percent body, percent square bracket, and I'll get rid of

77
00:04:58,420 --> 00:04:59,650
this button that I don't want.

78
00:05:01,180 --> 00:05:05,920
And I'll go down to the very bottom of the message and I'll update my footer to be whatever I want.

79
00:05:05,930 --> 00:05:07,680
So copyright is spelled wrong.

80
00:05:08,350 --> 00:05:09,640
Copy, right.

81
00:05:10,000 --> 00:05:12,010
I'll just put copy.

82
00:05:12,010 --> 00:05:12,490
Right.

83
00:05:13,060 --> 00:05:19,780
And then some year I'll put 20/20 and whatever else I could change the rest of this to whatever I wanted

84
00:05:19,780 --> 00:05:20,260
it to be.

85
00:05:21,010 --> 00:05:22,750
And that's all that I need to do.

86
00:05:22,750 --> 00:05:26,710
So I've now have a template I can use in my mail package.

87
00:05:27,040 --> 00:05:29,240
Let's go back to our go package here.

88
00:05:30,370 --> 00:05:32,230
I think I just change it in the wrong spot.

89
00:05:32,230 --> 00:05:32,590
I did.

90
00:05:32,590 --> 00:05:40,180
So I'll copy all of this, go back to my go project, open basic and select all delete and paste there.

91
00:05:40,180 --> 00:05:41,380
And that should be what I want.

92
00:05:41,380 --> 00:05:43,140
That should have my body tag and it does.

93
00:05:43,150 --> 00:05:43,570
All right.

94
00:05:43,570 --> 00:05:44,290
So I've got that.

95
00:05:44,980 --> 00:05:50,020
What I'm going to do when I send email is if I specify a template that I'll use that template.

96
00:05:50,020 --> 00:05:54,730
If I don't specify a template, I'll just send the way we did in the previous couple of lectures.

97
00:05:55,360 --> 00:05:58,510
So in order to make that happen, I need to open my models.

98
00:06:00,980 --> 00:06:10,030
Which is internal models open that up and I'm going to add a member or a field to this male data struct

99
00:06:10,130 --> 00:06:13,790
the type male data and I'll call it a template and it'll just be a string.

100
00:06:15,680 --> 00:06:18,290
And then I need to open my sendmail, go.

101
00:06:18,440 --> 00:06:20,120
I'm going to make some changes to this.

102
00:06:20,540 --> 00:06:26,060
And what I'm going to do is at this point where I set the body, I'm going to check to see if that template

103
00:06:26,090 --> 00:06:27,110
has been specified.

104
00:06:27,380 --> 00:06:33,140
So I'll say if my template is equal to nothing, then just do what we did before.

105
00:06:35,410 --> 00:06:38,260
Set the body using that line of code.

106
00:06:38,710 --> 00:06:46,060
Otherwise, if the template has been specified, I need to load it from disk and fortunately go like

107
00:06:46,060 --> 00:06:51,760
pretty much every decent programming language out there has built into the standard library utilities

108
00:06:51,760 --> 00:06:53,430
to read things from disk.

109
00:06:53,440 --> 00:06:54,760
And this is the simplest way to do it.

110
00:06:54,790 --> 00:06:55,880
I'm going to read some data.

111
00:06:55,900 --> 00:06:59,320
I'm going to read into the very variable data and potentially get an error.

112
00:06:59,770 --> 00:07:02,320
And I'm going to use the built in package.

113
00:07:02,350 --> 00:07:10,060
I owe util, input, output, utilities, and the function I want is called read file.

114
00:07:11,620 --> 00:07:14,020
And I'm going to read from a particular location.

115
00:07:14,050 --> 00:07:20,260
I know that my templates are going to be stored in my newly created folder called Email Templates,

116
00:07:20,260 --> 00:07:21,160
which is right up here.

117
00:07:22,240 --> 00:07:30,490
So I'll specify the path to that dot, which has started to level the project, go to email templates

118
00:07:31,240 --> 00:07:32,860
and then load a file.

119
00:07:32,860 --> 00:07:39,610
I don't use a placeholder as a string, which means I can just use format dot as print F and replace

120
00:07:39,610 --> 00:07:42,370
that placeholder with the name of the template.

121
00:07:44,300 --> 00:07:50,300
So that reads the template in the memory and it reads it in a way that we need to convert it, we need

122
00:07:50,300 --> 00:07:51,230
to convert it to a string.

123
00:07:51,240 --> 00:07:53,060
But first, let's check for our error.

124
00:07:53,090 --> 00:07:56,540
I'll just put if error is not equal to nil, then

125
00:07:59,150 --> 00:08:03,080
apt error log dot print line.

126
00:08:03,370 --> 00:08:04,210
I'll just print there.

127
00:08:04,970 --> 00:08:06,380
I know it's going to work because I know it's there.

128
00:08:07,940 --> 00:08:12,920
So now I need to convert this, this template that we've read off of disk.

129
00:08:12,920 --> 00:08:16,220
And if you look at the read file, what it returns is an array of bytes.

130
00:08:16,220 --> 00:08:18,590
I need to convert that to a string and we already know how to do that.

131
00:08:18,590 --> 00:08:26,480
So I'll just say male template is assigned the value of convert my string or convert into a string the

132
00:08:26,480 --> 00:08:27,680
data that I read off disk.

133
00:08:28,220 --> 00:08:34,130
So now I have that template, a memory, and now I want to replace that body placeholder that I put

134
00:08:34,130 --> 00:08:40,850
in there with the content that I have specified in the message mail data that I've sent to this particular

135
00:08:40,850 --> 00:08:41,240
function.

136
00:08:41,960 --> 00:08:47,390
And we can you think you could do that using format as print, but you can't I can't put a percent in

137
00:08:47,390 --> 00:08:48,990
there and substitute it.

138
00:08:48,990 --> 00:08:50,090
It just doesn't work.

139
00:08:50,180 --> 00:08:51,380
So we'll do it a different way.

140
00:08:52,040 --> 00:08:58,670
Message to send, which is a variable I'm creating, is going to be assign the value of from the strings

141
00:08:58,670 --> 00:09:00,680
package use replace.

142
00:09:02,810 --> 00:09:07,550
And that takes a number of arguments, the first one that takes is what is the string you want to do

143
00:09:07,550 --> 00:09:08,520
to replace in?

144
00:09:08,750 --> 00:09:11,960
Well, that's called Bill Template, the one we just read off disk.

145
00:09:12,380 --> 00:09:15,470
And then what is the text that you want to replace?

146
00:09:15,500 --> 00:09:22,270
And in this case, it's square bracket percent body percent closing square bracket.

147
00:09:22,610 --> 00:09:24,290
And what do you want to replace it with?

148
00:09:24,710 --> 00:09:29,150
And what I want to replace it with is whatever I passed as the content of my e-mail message, which

149
00:09:29,150 --> 00:09:30,440
is my content.

150
00:09:31,190 --> 00:09:32,750
And how many times do you want to do it?

151
00:09:32,840 --> 00:09:33,280
Once.

152
00:09:34,100 --> 00:09:40,370
So that will give me a message properly formatted using the template I read off disk and now I just

153
00:09:40,370 --> 00:09:43,010
assign that to the mail message I'm sending.

154
00:09:44,210 --> 00:09:46,610
And I do that by saying email don't set body.

155
00:09:47,630 --> 00:09:56,090
The type is from the mails, package, mail, dot, text, html and the content is message to send and

156
00:09:56,090 --> 00:09:56,990
that should do it.

157
00:09:57,440 --> 00:10:02,720
So let's go back and try formatting from our handlers.

158
00:10:03,050 --> 00:10:05,960
Let's try formatting the message we're sending to the Jeff's guest.

159
00:10:06,260 --> 00:10:14,750
OK, so up here, instead of saying just send this content, I'll now add a template and the template

160
00:10:14,750 --> 00:10:18,530
will be equal to the name of the template I want to use.

161
00:10:18,530 --> 00:10:22,340
That's inside my email templates folder, which I called basic HTML.

162
00:10:23,550 --> 00:10:27,810
That's going to be in quotation marks because the string basic HTML.

163
00:10:29,660 --> 00:10:35,330
All right, now let's stop our application, run our application, make sure it all compiles.

164
00:10:36,730 --> 00:10:44,070
And it does and I'll go back to my Web browser and I'll open mailbag, there's nothing in there.

165
00:10:44,080 --> 00:10:44,490
Good.

166
00:10:44,530 --> 00:10:50,860
I'll go to my nice page, I'll go to the home page and I'll create a new reservation and I'll do it

167
00:10:50,860 --> 00:10:51,880
for sometime in March.

168
00:10:53,230 --> 00:10:55,780
I'll make it the 10th to the 12th.

169
00:10:57,560 --> 00:11:07,280
Search availability, generals quarters, first name is Clark, last name is Kent Clark at Daily Planet

170
00:11:08,780 --> 00:11:16,010
Dotcom and some phone number, and that should send a nicely formatted e-mail message.

171
00:11:16,020 --> 00:11:18,700
And as I said, I'm not putting a lot of effort into making it pretty.

172
00:11:18,710 --> 00:11:19,640
I'll leave that up to you.

173
00:11:19,640 --> 00:11:24,410
You can read the documentation for the Foundation emails package and it's got great documentation,

174
00:11:24,410 --> 00:11:25,340
but let's see if it works.

175
00:11:26,600 --> 00:11:30,380
So we have a notification reservation.

176
00:11:30,380 --> 00:11:34,520
Notification should be the one for the the property owner, which should be ugly.

177
00:11:34,520 --> 00:11:35,240
And it is.

178
00:11:35,660 --> 00:11:39,440
And let's look at this one and that's format a little bit better.

179
00:11:39,450 --> 00:11:43,280
Now, obviously, I left some things in there that I should probably pull out those placeholders.

180
00:11:43,640 --> 00:11:49,760
But the point is now I have complete control over the way that my email message looks, and it seems

181
00:11:49,760 --> 00:11:51,110
to work very, very well.

182
00:11:52,040 --> 00:11:58,670
So you can modify that basic HTML template to look exactly the way that you want and you're off to the

183
00:11:58,670 --> 00:12:00,270
races and that's all there is to it.

184
00:12:00,290 --> 00:12:02,210
So experiment with that.

185
00:12:02,210 --> 00:12:07,190
If you're interested in making nicely formatted email message and bear in mind that the foundation package

186
00:12:07,190 --> 00:12:08,530
is not the only one out there.

187
00:12:08,540 --> 00:12:09,320
You may like it.

188
00:12:09,320 --> 00:12:09,890
You may not.

189
00:12:09,890 --> 00:12:14,600
I find it works really, really well for my purposes, but it's entirely up to you.
