1 00:00:00,720 --> 00:00:05,730 In the last video we continue to working on our mailer specifically the constructor function which does 2 00:00:05,730 --> 00:00:10,680 some initial set up of any instance of the mailer that we create inside of here. 3 00:00:10,710 --> 00:00:16,150 We've started to define a couple of different properties that are required by the Meilleur to work correctly. 4 00:00:16,460 --> 00:00:22,080 So our Meilleur expects us to have a from email property that contains exactly who is sending the email 5 00:00:22,470 --> 00:00:27,330 and expects to have a subject that will be used as the subject of the e-mail and we'll expects a body 6 00:00:27,330 --> 00:00:34,290 property that it's some H email display inside the email and then also expects a recipient property 7 00:00:34,650 --> 00:00:39,480 which is going to be exactly who the email should be sent off to. 8 00:00:39,480 --> 00:00:44,970 Now in every case here except for the subject one we have obviously had to apply some type of helper 9 00:00:45,000 --> 00:00:45,920 to this thing. 10 00:00:46,320 --> 00:00:53,400 So help or does e-mail help or not content are to helper functions from the censored library that properly 11 00:00:53,400 --> 00:01:00,390 format both the from e-mail and the body of the e-mail to work correctly inside of an actual e-mail 12 00:01:00,480 --> 00:01:02,870 that is being processed by send great. 13 00:01:02,970 --> 00:01:09,200 We're about to do something very similar for sending up the list of recipients for this e-mail. 14 00:01:09,900 --> 00:01:15,390 Now before we do that I want to remind you that at this point the arguments recipients right here is 15 00:01:15,600 --> 00:01:23,840 the recipients property from our survey instance and that recipients property very importantly. 16 00:01:24,010 --> 00:01:26,150 You'll recall was find our diagram for it. 17 00:01:26,160 --> 00:01:29,150 I know we just had this thing up where to go. 18 00:01:29,190 --> 00:01:30,010 Here it is right here. 19 00:01:30,210 --> 00:01:36,990 So we've got our survey for instance the recipient's property is an array of objects where each object 20 00:01:37,200 --> 00:01:39,610 has an email property. 21 00:01:39,870 --> 00:01:41,880 So an email key value pair. 22 00:01:41,940 --> 00:01:46,980 So we need to make sure that we somehow format this sub document collection that we just passed into 23 00:01:46,980 --> 00:01:51,650 this thing to make sure that we extract just the actual e-mail addresses. 24 00:01:51,720 --> 00:01:52,170 OK. 25 00:01:52,320 --> 00:01:55,140 So give me the next challenge that we have to kind of get over. 26 00:01:55,380 --> 00:02:00,690 So we want to make sure we extract each of the these e-mails from these objects inside of the sub document 27 00:02:00,690 --> 00:02:01,810 collection. 28 00:02:02,460 --> 00:02:09,100 So that's going to be what this format addresses function is for. 29 00:02:09,120 --> 00:02:13,340 So we're going to add on this helper function called format addresses. 30 00:02:13,560 --> 00:02:22,050 So format addresses that we receive our list of recipients and then inside of the function we're going 31 00:02:22,050 --> 00:02:24,930 to iterate through the list of recipients. 32 00:02:25,100 --> 00:02:30,710 And for every recipient we will extract just the email and then return it. 33 00:02:30,930 --> 00:02:34,290 We will then return that overall array that we have created. 34 00:02:34,290 --> 00:02:42,960 So I'm going to say return recipients dot map remember that every recipient inside of this function 35 00:02:42,990 --> 00:02:47,730 is an object that contains an email property and we just care about that email here. 36 00:02:47,790 --> 00:02:51,900 So we're going to use some 60 structuring to just pull off that e-mail. 37 00:02:52,050 --> 00:02:58,050 So I'm going to place another set of parentheses and then a set of curly braces and say Give me just 38 00:02:58,050 --> 00:03:02,410 the email like so now very important here. 39 00:03:02,550 --> 00:03:07,220 If you do use the structure right here make sure you get the extra set of parentheses around here. 40 00:03:07,320 --> 00:03:12,450 Otherwise you're going to see an error message because you can't have destructuring with an arrow function 41 00:03:13,290 --> 00:03:14,390 without the parentheses. 42 00:03:14,400 --> 00:03:18,340 You have to have the parentheses to do destructuring with an air of function. 43 00:03:18,400 --> 00:03:18,720 OK. 44 00:03:18,750 --> 00:03:24,950 So now inside of the mapping statement itself we're going to take the e-mail we're going to return it. 45 00:03:25,080 --> 00:03:30,750 But before we do we're going to do a little bit of formatting on the e-mail just like we did up here 46 00:03:31,260 --> 00:03:32,450 as well. 47 00:03:32,490 --> 00:03:42,090 So from the body of the arrow function we'll say return new helper Daut capital E mail and we'll pass 48 00:03:42,090 --> 00:03:47,270 in the e-mail that we just extracted. 49 00:03:47,270 --> 00:03:53,400 OK so here we go again we're taking in the list of recipients which is our sub document collection. 50 00:03:53,400 --> 00:03:58,460 We pass it off to format addresses for every recipient inside that array. 51 00:03:58,530 --> 00:04:04,260 We pull off the e-mail property we format it with the email helper and then we return it. 52 00:04:04,260 --> 00:04:11,870 So now recipients right here start recipients we can imagine is going to be an array of these new help 53 00:04:11,870 --> 00:04:18,410 or don't e-mail things each of which wrap an actual e-mail that we want to send this e-mail off to. 54 00:04:18,450 --> 00:04:19,950 That's a lot of saying e-mail. 55 00:04:19,990 --> 00:04:21,260 I just said e-mail a lot. 56 00:04:21,270 --> 00:04:22,970 I'm not going to say it anymore. 57 00:04:23,200 --> 00:04:24,260 So I'm going to try not to you. 58 00:04:24,300 --> 00:04:25,280 I doubt I can. 59 00:04:25,290 --> 00:04:26,850 But whatever. 60 00:04:26,850 --> 00:04:27,340 OK. 61 00:04:27,540 --> 00:04:32,700 So this now has formatted and assigned all of our recipients to this dot recipients we're now ready 62 00:04:32,700 --> 00:04:34,530 to move on to the next step. 63 00:04:34,530 --> 00:04:41,460 So we set up our for kind of like golden properties here with e-mails from what the subject is the body 64 00:04:41,460 --> 00:04:44,640 of it and the list of who to send it to. 65 00:04:44,640 --> 00:04:47,240 Now there's one or two more steps we have to do. 66 00:04:47,250 --> 00:04:50,590 We're going to do them in order of increasing difficulty. 67 00:04:50,910 --> 00:04:56,400 So the first thing we're going to do is to make sure that the body right here this body we're going 68 00:04:56,400 --> 00:05:00,870 to make sure that that gets added as the actual content to the mailer. 69 00:05:00,900 --> 00:05:05,730 So just assigning the content here to the body property is not enough. 70 00:05:05,760 --> 00:05:11,430 We have to actually kind of register this body with the email with the mailer itself. 71 00:05:11,490 --> 00:05:21,450 So to do so we'll say this dot ad content will pass in this body like so now when you see this you're 72 00:05:21,450 --> 00:05:26,640 going to say OK this is a helper function that we have to put together like we have to make a helper 73 00:05:26,640 --> 00:05:28,110 function called out content. 74 00:05:28,140 --> 00:05:29,970 And we're going to do something inside of there. 75 00:05:30,400 --> 00:05:31,740 Oh no not quite. 76 00:05:31,740 --> 00:05:35,860 Remember that our mailer is extending help or direct mail. 77 00:05:36,000 --> 00:05:41,410 So this mail base class right here it has some built in functionality to it. 78 00:05:41,430 --> 00:05:43,850 This is one of those built in functions. 79 00:05:44,010 --> 00:05:49,770 So the mail class right here has a function called ad content and it expects you to call ad content 80 00:05:50,040 --> 00:05:52,500 with the actual body that you want to use in the mail. 81 00:05:52,920 --> 00:05:58,200 So at this point you can easily imagine that we could have refactored our code here to not assign anything 82 00:05:58,200 --> 00:06:04,140 to this body we could've just said well yeah just you know do the content thing and then call add content 83 00:06:04,140 --> 00:06:05,550 with it just like this. 84 00:06:05,550 --> 00:06:08,670 Right we could just skip this entire body step right here. 85 00:06:09,030 --> 00:06:10,010 Well we definitely could. 86 00:06:10,020 --> 00:06:15,750 But personally I like how the mailer looks when we very clearly assign each of these properties and 87 00:06:15,750 --> 00:06:19,730 then we make use of each of the properties later on down the constructor function. 88 00:06:19,950 --> 00:06:24,100 It just makes it really easy to kind of feel the flow of code inside the mailer. 89 00:06:24,180 --> 00:06:28,620 Again a lot of the code that we're putting together inside of here my best explanation I can give to 90 00:06:28,620 --> 00:06:33,110 you is kind of this is how we have to do it with with grid. 91 00:06:33,210 --> 00:06:35,610 And unfortunately that's kind of the reality here. 92 00:06:36,040 --> 00:06:36,440 OK. 93 00:06:36,480 --> 00:06:38,890 So two more steps here. 94 00:06:38,910 --> 00:06:40,760 Let's take care of the easier one next. 95 00:06:40,920 --> 00:06:47,060 Right underneath our content we're now going to enable click tracking inside of our email. 96 00:06:47,160 --> 00:06:54,270 So remember we had said that any time we put an email or give me a link into one of our emails send 97 00:06:54,270 --> 00:06:59,370 great grade We'll scan the email and automatically replace every one and there's every link with one 98 00:06:59,370 --> 00:07:01,680 of their special own links. 99 00:07:01,740 --> 00:07:05,280 And so that's what this clicked tracking thing that we're about to do is click. 100 00:07:05,280 --> 00:07:10,950 Tracking is going to essentially enable this step right here. 101 00:07:10,960 --> 00:07:17,580 So back inside of our mailer will say this dot ad click tracking. 102 00:07:17,610 --> 00:07:21,520 Now this is going to be in a helper function that you and I are going to define. 103 00:07:21,630 --> 00:07:29,090 So now underneath format addresses we're going to say ad click tracking inside of here. 104 00:07:29,130 --> 00:07:33,870 We're going to create two helper variables and then use them to do a little bit of setup. 105 00:07:33,930 --> 00:07:45,000 So we'll say Konst tracking settings is new helper dot tracking settings like so then Konst click tracking 106 00:07:45,540 --> 00:07:48,700 is new helper Daut click tracking. 107 00:07:48,840 --> 00:07:55,290 And we're going to pass in the arguments of true and true Okay now we're going to make use of these 108 00:07:55,290 --> 00:07:56,870 two variables. 109 00:07:57,180 --> 00:08:01,350 We're going to say trackings settings Daut set. 110 00:08:01,350 --> 00:08:07,310 Click tracking and pass in click tracking. 111 00:08:07,380 --> 00:08:12,750 So essentially take that one variable that we just declared and pass in the second one that we just 112 00:08:12,750 --> 00:08:13,620 defined as well. 113 00:08:13,770 --> 00:08:20,290 So click check or check settings track settings click tracking click tracking and then one last line 114 00:08:20,290 --> 00:08:28,210 and here this dot ad tracking settings tracking settings like so. 115 00:08:28,640 --> 00:08:29,050 OK. 116 00:08:29,070 --> 00:08:32,310 So again I know this is painful stuff to write right here. 117 00:08:32,310 --> 00:08:39,120 I know I feel terrible just writing it and saying hey this is just how centered works but unfortunately 118 00:08:39,150 --> 00:08:44,460 this is basically how some grid works and I don't have a great explanation for you on you know the real 119 00:08:44,460 --> 00:08:46,230 internals of what's going on here. 120 00:08:46,260 --> 00:08:50,820 At best I could say read the documentation but the unfortunate thing is the documentation basically 121 00:08:50,820 --> 00:08:52,780 says just write this code. 122 00:08:52,830 --> 00:08:54,510 And that's pretty much it. 123 00:08:54,510 --> 00:08:57,990 So hey for better for worse this is what we got to do. 124 00:08:58,890 --> 00:08:59,160 All right. 125 00:08:59,160 --> 00:09:04,140 Now there's one last little piece of setup that we need to do starting inside the constructor. 126 00:09:04,140 --> 00:09:08,780 So this is going to be one of the more challenging ones just to kind of understand what's going on. 127 00:09:08,790 --> 00:09:10,760 But the code itself won't be too bad. 128 00:09:11,070 --> 00:09:13,610 So we're going to do the function call first. 129 00:09:13,680 --> 00:09:17,770 We're going to call it this dot add recipients. 130 00:09:18,000 --> 00:09:20,050 And I think at this point we'll take a quick break. 131 00:09:20,070 --> 00:09:22,500 When we come back we're going to implement this. 132 00:09:22,540 --> 00:09:25,780 Recipient's function right here inside of our mailer. 133 00:09:25,890 --> 00:09:28,890 So a quick break and I'll see you in just a minute.