1
00:00:00,120 --> 00:00:07,740
In this video, we are going to create a script that sends a single email from one email address to

2
00:00:07,740 --> 00:00:09,210
another email address.

3
00:00:09,570 --> 00:00:17,490
So I am inside the ripple here, inside this empty folder, and I'm going to create a new repo using

4
00:00:17,490 --> 00:00:22,290
Python as a programming language and give a meaningful name.

5
00:00:24,860 --> 00:00:25,690
To my report.

6
00:00:26,840 --> 00:00:27,380
Create.

7
00:00:28,930 --> 00:00:30,910
And this is the repeal environment.

8
00:00:30,940 --> 00:00:33,610
I will work on just a friendly reminder.

9
00:00:33,610 --> 00:00:40,000
If you enter this, you are in your browser with the hash main, that's p port.

10
00:00:40,360 --> 00:00:46,270
Then you can fork this a ripple to have the same environment as me in a ripple.

11
00:00:46,270 --> 00:00:47,680
And then you can start coding.

12
00:00:48,670 --> 00:00:58,150
And if you add dash done at the end of the URL, you will have access to the wrapper with the completed

13
00:00:58,150 --> 00:00:58,570
code.

14
00:00:59,290 --> 00:01:01,720
That ripple is also fungible.

15
00:01:01,720 --> 00:01:07,060
So you can for kids, you can copy it and use it as it is and let's start coding.

16
00:01:07,060 --> 00:01:14,350
But before, let me make sure that you understand how sending emails works in our daily life.

17
00:01:14,350 --> 00:01:20,680
We use things like Gmail or Outlook or other email clients.

18
00:01:20,890 --> 00:01:23,080
So these are email clients.

19
00:01:23,080 --> 00:01:31,030
They are apps, desktop apps or web apps which allow us to see our emails and also sends out and receive

20
00:01:31,030 --> 00:01:31,570
emails.

21
00:01:31,630 --> 00:01:39,670
Now these email clients, these applications, they use a protocol calls SMTP.

22
00:01:39,700 --> 00:01:47,890
So simple mail transfer protocol SMTP makes it possible to send and receive emails.

23
00:01:47,980 --> 00:01:57,280
So when we want to create a Python app that sends out emails, we need to use SMTP as well, just like

24
00:01:57,370 --> 00:02:00,100
these other email clients do.

25
00:02:00,130 --> 00:02:11,230
And to use SMTP, you need to use a package which basically offers us an c p python object to configure.

26
00:02:11,650 --> 00:02:14,380
So we're going to use your Gmail.

27
00:02:14,530 --> 00:02:15,370
Let's install it.

28
00:02:16,600 --> 00:02:18,580
Why a gmail?

29
00:02:20,530 --> 00:02:28,540
So as the name suggests, this package works only to send out emails from a Gmail account.

30
00:02:28,810 --> 00:02:32,890
Therefore, I expect that you have a Gmail account open already.

31
00:02:33,040 --> 00:02:42,210
As we wait for the installation to complete, I'm going to import your Gmail right now that it is installed.

32
00:02:42,220 --> 00:02:48,580
We have that in our namespace so we can use on the fly code introspection.

33
00:02:48,880 --> 00:02:57,590
Before we do anything, let's prepare some variables where we stole the email information, which is

34
00:02:57,590 --> 00:03:05,020
the sender email address, the receiver email address, the subject of the email and the content of

35
00:03:05,020 --> 00:03:05,620
the email.

36
00:03:06,010 --> 00:03:08,680
So Sender will be.

37
00:03:08,680 --> 00:03:16,020
In my case, I have created a throwaway email account on Gmail just for this app.

38
00:03:16,330 --> 00:03:20,050
The name is a bit strange, but it's an email address.

39
00:03:21,220 --> 00:03:22,060
The receiver.

40
00:03:22,300 --> 00:03:28,030
The receiver is going to be a temporary email account that I can get from this site.

41
00:03:28,570 --> 00:03:31,150
Drop mail dot any.

42
00:03:31,180 --> 00:03:43,180
So this is my disposable email address going to copied and pasted in the receiver variable, the subject

43
00:03:43,180 --> 00:03:43,930
of the email.

44
00:03:47,290 --> 00:03:51,370
So that should do it the contents of the email.

45
00:03:51,460 --> 00:03:58,660
This makes sense to be a multi-line string since this would be a long text split.

46
00:03:58,720 --> 00:04:05,650
And here is the contents of the all the email.

47
00:04:06,340 --> 00:04:06,640
Hi.

48
00:04:07,450 --> 00:04:10,560
So that's the text of the email body.

49
00:04:10,780 --> 00:04:22,210
Once we have these, we want to create an empty P object instance using the s and t p class which takes

50
00:04:22,210 --> 00:04:25,600
as arguments a user so the user is the sender.

51
00:04:27,310 --> 00:04:37,210
If passwords also, it's not a good idea to write passwords in plain python code because others may

52
00:04:37,210 --> 00:04:38,110
see them.

53
00:04:38,110 --> 00:04:46,960
So it's safer as we are earning a repo, it's safer to store them as environment variables.

54
00:04:47,800 --> 00:04:56,860
So you go to this key icon here, press that you have some information here which says that you can

55
00:04:57,100 --> 00:04:59,170
hide passwords using this tool.

56
00:04:59,740 --> 00:05:08,620
Key is basically the name that we will be using from our Python code to refer to the actual password,

57
00:05:08,620 --> 00:05:10,300
which we're going to store in here.

58
00:05:10,750 --> 00:05:15,820
So key, it makes sense to have this under the name passwords.

59
00:05:16,000 --> 00:05:24,850
Usually we use capital letters for these keys, and the actual passwords has to be a Gmail app passwords.

60
00:05:25,060 --> 00:05:31,090
The normal Gmail passwords that you use to log in to your Gmail account will not work here.

61
00:05:31,660 --> 00:05:35,800
So you need to create a Gmail app passwords for that.

62
00:05:35,800 --> 00:05:43,300
You need to go to your Gmail account, then go to your manage your Google account button.

63
00:05:44,600 --> 00:05:52,040
So there you see the settings of your account and you want to go to security and then you want to scroll

64
00:05:52,040 --> 00:05:54,500
down to signing to queue.

65
00:05:54,770 --> 00:06:03,350
And then first you want to turn on two step verification if if that is turned off, so get started to

66
00:06:03,350 --> 00:06:04,010
turn it on.

67
00:06:08,640 --> 00:06:13,230
You need to enter a phone number here to be able to turn on two step verification.

68
00:06:16,050 --> 00:06:25,850
So turn on two step verification, then go back to the security page and then down here below to simplification,

69
00:06:25,860 --> 00:06:28,350
you should normally see this app password section.

70
00:06:28,620 --> 00:06:29,580
You want to click there.

71
00:06:30,550 --> 00:06:33,190
Answer the password of your Gmail account again.

72
00:06:35,920 --> 00:06:39,520
And then you want to create an app here.

73
00:06:39,820 --> 00:06:45,460
So select app you can choose either puts a name for your app.

74
00:06:48,640 --> 00:06:50,920
Like Python automation generates.

75
00:06:51,580 --> 00:06:57,310
And what you see here is going to be your app passwords with all the spaces.

76
00:06:57,310 --> 00:07:00,000
So please note without the spaces.

77
00:07:00,010 --> 00:07:04,030
So you want to copy that and go back to rappel.

78
00:07:05,610 --> 00:07:09,210
And you want to paste that password in this box here.

79
00:07:13,330 --> 00:07:19,640
Press adds new secrets and that key value secret is added.

80
00:07:20,340 --> 00:07:28,900
The way to use it now is by first importing the OS library, which gives you access to always that gets.

81
00:07:29,470 --> 00:07:33,830
And so you see this method now expects a key.

82
00:07:33,830 --> 00:07:34,630
Yes argument.

83
00:07:35,620 --> 00:07:37,570
The key has to come as a string.

84
00:07:38,080 --> 00:07:40,720
So that is pass words.

85
00:07:41,950 --> 00:07:43,330
The name of my key.

86
00:07:44,300 --> 00:07:44,600
Right.

87
00:07:44,600 --> 00:07:52,070
So the user, which is a sensor, the passwords of that sensor email address.

88
00:07:52,820 --> 00:07:59,060
And so now we read it's who sends out this email to whom.

89
00:08:00,020 --> 00:08:02,480
Well, we have this two arguments here.

90
00:08:02,480 --> 00:08:09,830
So two is equal to a string, which in our case is stored in this receiver variable.

91
00:08:09,830 --> 00:08:12,950
So I'm just going to paste that receiver variable there.

92
00:08:13,280 --> 00:08:14,210
What else do we have?

93
00:08:14,210 --> 00:08:18,290
Subjects subject is equal to that's valuable.

94
00:08:18,290 --> 00:08:20,270
So copy that piece of two.

95
00:08:21,620 --> 00:08:29,480
And what else contents is equal to that contents of variable copy pasted there.

96
00:08:30,440 --> 00:08:36,320
And these are all the arguments we need to pass to be able to send out an email.

97
00:08:37,940 --> 00:08:46,220
Lastly, I'm just going to putting out a message here on the command line just to visually see that's

98
00:08:46,490 --> 00:08:53,030
the script actually Iran and Iran email sent.

99
00:08:53,900 --> 00:08:56,840
Let's check this email address now.

100
00:08:56,840 --> 00:09:06,440
So the receiver, which is this temporary email address and yes, we did receive an email, here is

101
00:09:06,440 --> 00:09:08,630
the contents of the email.

102
00:09:09,410 --> 00:09:09,890
Hi.

103
00:09:11,190 --> 00:09:15,120
Now if this email client doesn't show emails in a very nice way.

104
00:09:15,120 --> 00:09:19,220
So that's why we see this email tax here.

105
00:09:20,010 --> 00:09:22,920
But we did receive the email successfully.

106
00:09:23,280 --> 00:09:28,860
Thank you for watching this video and please go to the next one and I'll talk to you there.

