1
1

00:00:01,100  -->  00:00:02,950
<v Jose>Hi guys, and welcome back.</v>
2

2

00:00:02,950  -->  00:00:04,080
In this video we're quickly going
3

3

00:00:04,080  -->  00:00:07,470
to talk about sending emails.
4

4

00:00:07,470  -->  00:00:08,890
We're going to be using this service
5

5

00:00:08,890  -->  00:00:11,020
called Mailgun to send emails,
6

6

00:00:11,020  -->  00:00:12,440
but there's a lot of them, like
7

7

00:00:12,440  -->  00:00:14,313
SendGrid is another example.
8

8

00:00:15,430  -->  00:00:19,430
These email services have API's,
9

9

00:00:19,430  -->  00:00:22,540
and what that means is you can send them some data
10

10

00:00:22,540  -->  00:00:25,300
in a format that they understand and they expect,
11

11

00:00:25,300  -->  00:00:27,060
and they'll do something for you.
12

12

00:00:27,060  -->  00:00:28,313
That's what an API is.
13

13

00:00:29,250  -->  00:00:31,200
In this case, when you send them the data
14

14

00:00:31,200  -->  00:00:34,212
that they expect, Mailgun will send an email
15

15

00:00:34,212  -->  00:00:36,683
to the email address that you tell them to.
16

16

00:00:38,490  -->  00:00:41,400
If you go to Mailgun.com, here you can see
17

17

00:00:41,400  -->  00:00:44,426
some of the example languages
18

18

00:00:44,426  -->  00:00:47,260
and Python is one of them, which is quite nice
19

19

00:00:47,260  -->  00:00:50,480
because it tells us exactly how to use their service
20

20

00:00:50,480  -->  00:00:51,863
to send an email.
21

21

00:00:53,400  -->  00:00:55,150
Something important to note is that
22

22

00:00:55,150  -->  00:00:58,310
this depends on the Requests library,
23

23

00:00:58,310  -->  00:01:01,838
which is now really the standard way of sending data
24

24

00:01:01,838  -->  00:01:05,640
through the internet to another web service.
25

25

00:01:05,640  -->  00:01:08,888
So, if we instal the Requests module, which we will do,
26

26

00:01:08,888  -->  00:01:12,280
then we can send some data in this format
27

27

00:01:13,560  -->  00:01:15,710
and Mailgun will send an email.
28

28

00:01:15,710  -->  00:01:18,950
And how they send an email, we don't care about
29

29

00:01:18,950  -->  00:01:21,713
because that's what the API is for.
30

30

00:01:22,730  -->  00:01:24,610
So, a couple of things that we need is
31

31

00:01:24,610  -->  00:01:26,800
we need to sign up and we need to get
32

32

00:01:26,800  -->  00:01:29,830
the data that they require.
33

33

00:01:29,830  -->  00:01:34,830
That is a URL, something that we send data to,
34

34

00:01:35,330  -->  00:01:39,000
an API key, that's used to uniquely identify us
35

35

00:01:39,000  -->  00:01:41,408
as the makers of a request.
36

36

00:01:41,408  -->  00:01:44,740
And then who the email is from,
37

37

00:01:44,740  -->  00:01:46,610
who the email is to,
38

38

00:01:46,610  -->  00:01:50,260
a subject for the email, and some text.
39

39

00:01:50,260  -->  00:01:52,950
Optionally, we could also include some HTML
40

40

00:01:52,950  -->  00:01:55,793
in the email, if we want, to make it a little bit nicer.
41

41

00:01:57,250  -->  00:01:59,720
So, if you do go ahead and sign up,
42

42

00:01:59,720  -->  00:02:01,840
that will get you an account
43

43

00:02:01,840  -->  00:02:04,530
and you do have to give them some information
44

44

00:02:04,530  -->  00:02:05,770
but you don't have to give them
45

45

00:02:05,770  -->  00:02:07,810
payment information, if you want.
46

46

00:02:07,810  -->  00:02:10,950
But, if you don't give them a credit card
47

47

00:02:10,950  -->  00:02:12,490
you are restricted to send email
48

48

00:02:12,490  -->  00:02:15,080
to Authorised Recipients only.
49

49

00:02:15,080  -->  00:02:17,170
That means that you have to add your email
50

50

00:02:17,170  -->  00:02:19,400
as an Authorised Recipient, in order to be able
51

51

00:02:19,400  -->  00:02:22,180
to receive emails, otherwise it will fail.
52

52

00:02:22,180  -->  00:02:23,900
If you do give them the credit card,
53

53

00:02:23,900  -->  00:02:25,990
that does not mean they're going to charge you.
54

54

00:02:25,990  -->  00:02:29,110
There is quite a generous limit of free emails
55

55

00:02:29,110  -->  00:02:31,610
that you can send before they start charging you
56

56

00:02:31,610  -->  00:02:33,500
and they are quite nice with the limits
57

57

00:02:33,500  -->  00:02:34,720
and so on, so if you do go over
58

58

00:02:34,720  -->  00:02:36,660
a little bit, it doesn't really matter.
59

59

00:02:36,660  -->  00:02:38,290
The limit, as I said, is quite generous,
60

60

00:02:38,290  -->  00:02:42,850
I have yet to go over the limit myself, so there you go.
61

61

00:02:42,850  -->  00:02:45,700
Just make an account and then we can look
62

62

00:02:45,700  -->  00:02:48,050
at what you'll see once you've made an account.
63

63

00:02:50,420  -->  00:02:51,940
Once you've logged into Mailgun,
64

64

00:02:51,940  -->  00:02:55,070
you'll see something that looks more or less like this.
65

65

00:02:55,070  -->  00:02:57,310
Some things may be slightly different,
66

66

00:02:57,310  -->  00:03:01,670
but one of the things will be the Sandbox Domains.
67

67

00:03:01,670  -->  00:03:04,800
This is what we're gonna use to test our application.
68

68

00:03:04,800  -->  00:03:07,470
So, do click on Authorised Recipients
69

69

00:03:08,470  -->  00:03:10,680
and make sure that your email has been added.
70

70

00:03:10,680  -->  00:03:11,810
You'll have to invite yourself
71

71

00:03:11,810  -->  00:03:13,550
and then click a link on the email.
72

72

00:03:13,550  -->  00:03:16,400
That way you can really make sure that it's working
73

73

00:03:16,400  -->  00:03:18,517
before you decide to go down the
74

74

00:03:18,517  -->  00:03:20,215
"create your own domain" route,
75

75

00:03:20,215  -->  00:03:22,083
which we'll look at later on.
76

76

00:03:23,920  -->  00:03:26,320
If you click on the domain,
77

77

00:03:26,320  -->  00:03:29,070
then you'll see some information.
78

78

00:03:29,070  -->  00:03:31,680
We will need this in order to send email.
79

79

00:03:31,680  -->  00:03:34,530
One of those things is the API key,
80

80

00:03:34,530  -->  00:03:36,800
another one is the URL.
81

81

00:03:36,800  -->  00:03:38,120
So, we'll need both of these
82

82

00:03:38,120  -->  00:03:40,083
in order to be able to send our emails.
83

83

00:03:41,000  -->  00:03:44,550
Notice that there is some sort of email account here,
84

84

00:03:44,550  -->  00:03:47,310
but you don't need this one for anything.
85

85

00:03:47,310  -->  00:03:49,740
So, that's just if you want to log into this account
86

86

00:03:49,740  -->  00:03:52,400
through an email client, which we don't want to do.
87

87

00:03:52,400  -->  00:03:55,523
So, all we need is the API key and the URL.
88

88

00:03:56,880  -->  00:03:58,140
Once you've got those two, and you've
89

89

00:03:58,140  -->  00:04:00,550
added yourself as an Authorised Recipient
90

90

00:04:00,550  -->  00:04:02,290
we're ready to move onto the next video
91

91

00:04:02,290  -->  00:04:03,870
where we're going to start sending email
92

92

00:04:03,870  -->  00:04:05,840
from within our app.
93

93

00:04:05,840  -->  00:04:06,790
I'll see you there.
