Skip to content

Commit ae9a688

Browse files
authored
Merge pull request larymak#8 from Dhrumil-Zion/main
Sending Email Utility Added
2 parents 6d697f2 + 5c0f2e2 commit ae9a688

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Sending-Emails/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Sending Email
2+
3+
## Description
4+
This snippet of code will send emails from your account to one or multiple accounts.
5+
6+
## Requirements
7+
8+
`$ pip install emails`
9+
10+
`$ pip install secure-smtplib`
11+
12+
## Steps To Execution
13+
- First of all you need to Enable Less Secure app access from your sending email account. [(Click Here for reference !!)](https://youtu.be/Ee7PDsbfOUI)
14+
- Fork this repo and navigate to Sending-Email folder
15+
- Open code.py in any text/code editor
16+
- Write necessary modification in code like your mail-id , password , reciever's mail id , send file name etc..
17+
- Run this code.py `$ python code.py`
18+
- Check if reciever got the mails or not !!!
19+
20+
## Extra
21+
- Note that you can send emails to multiple accounts by adding [email1,email2.email3,..,emailN] to (TO:) section in code.
22+
- I have aaded HTML using add_alternative, so it will work for sending emails using html formats.
23+
- I have also added add_attachments so that you can send files with email
24+
- Those who don't want any functionality, fill free to comment out that portion of code.

Sending-Emails/code.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
###### Notice ######
2+
3+
# before sending email you have to enable your less secure apps access in your sending mail ([email protected])
4+
5+
import smtplib
6+
from email.message import EmailMessage
7+
8+
EMAIL_ADDRESS = "[email protected]" # your email-id goes here
9+
EMAIL_PASSWORD = "xyz" # your password goes here
10+
11+
msg = EmailMessage()
12+
msg['Subject'] = 'this is subject'
13+
msg['From'] = EMAIL_ADDRESS
14+
msg['To'] = EMAIL_ADDRESS
15+
16+
msg.set_content('Content area')
17+
18+
msg.add_alternative("""\
19+
<html>
20+
<body>
21+
<h1>Your HTML CONTENT GOES HERE </h1>
22+
</body>
23+
</html>
24+
""", subtype='html')
25+
26+
with open('testing.txt', 'rb') as f: # your filename will go here
27+
file_data = f.read()
28+
file_name = f.name
29+
30+
msg.add_attachment(file_data, maintype='application', subtype='octet-stream', filename=file_name)
31+
32+
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
33+
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
34+
35+
smtp.send_message(msg)
36+
print("Email Sent Successfully ..")

Sending-Emails/testing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is for testing purpose

0 commit comments

Comments
 (0)