This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
Email Plugin #62
Merged
Merged
Email Plugin #62
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78786be
Added in email plugin, fixed passgen plugin, and changed main.py to l…
TannerFry 3173d48
Updatied Email plugin to allow multiple word for body and subject, an…
TannerFry 432dd02
added in documentation for README, mail.py, and email_config.conf
TannerFry 5e93530
changed passgen back
TannerFry 8930759
Update CONNECT.conf
TannerFry d2f09e6
Update main.py
TannerFry File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
server_url = chat.freenode.net | ||
port = 6667 | ||
name = hb_tst00 | ||
name = hb_tst00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ dictionary | |
password_generator | ||
bitcoin | ||
wikipedia | ||
weather | ||
weather | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#put your email to send from after "Email: ", make sure that there is atleast 1 space | ||
#between "Email:" and your email. | ||
|
||
Email: email@email.com | ||
|
||
#put your email password and make sure that there is at least 1 space between "Password:" | ||
#and your password | ||
|
||
Password: password | ||
|
||
#put your email service provider's SMTP server. The default will be "smtp.office365.com" | ||
#which is used for outlook and hotmail emails. Make sure there is at least 1 space between | ||
#"Server:" and the server name. | ||
|
||
SMTP Server: smtp.office365.com | ||
|
||
#put your email service provider's SMTP server's port. The default will be "587" which | ||
#is the port for the "smtp.office365.com". Make sure there is at least 1 space between | ||
#"Port:" and the port number. | ||
|
||
SMTP Server Port: 587 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
[mail.py] | ||
Email plugin | ||
|
||
[Author] | ||
Tanner Fry | ||
|
||
[About] | ||
Will allow the user to send an email while in the chat | ||
with the bot. The text send will be interpreted as html | ||
so you can use formatting such as <br> to make new lines, | ||
and any other html formatting commands in the text of the | ||
body of the email. No additional libraries need to be installed. | ||
Make sure that you configure the email_config.conf file with your | ||
email, your email password, SMTP server, and SMTP server port. | ||
See that document for more information. | ||
|
||
[Commands] | ||
.mail <To email address> .body <Text for the body of your email> .subject <Text of subject for email> | ||
EX:// ".mail test@email.com .body testing body for honeybot email .subject testing subject" | ||
|
||
""" | ||
import smtplib | ||
import string | ||
from email.mime.text import MIMEText | ||
|
||
#open config file for user credentials to email | ||
f = open("email_config.conf") | ||
str = f.read() | ||
f.close() | ||
|
||
#split the read in words into a list, and pop them into their respective | ||
#variables | ||
test = str.rsplit() | ||
USER = test[test.index("Email:")+1] | ||
PASS = test[test.index("Password:")+1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using config parser better here |
||
HOST = test[test.index("Server:")+1] | ||
PORT = test[test.index("Port:")+1] | ||
|
||
#used to tie into the body of what the user sends, if this is not at the | ||
#front of the message then the message will not appear in the email | ||
text = "\n" | ||
|
||
class Plugin: | ||
def __init__(self): | ||
pass | ||
|
||
#__email will take 6 parameters to setup the email reconnection | ||
#and send the message. | ||
def __email(HOST, PORT, USER, PASS, TO, MSG): | ||
server = smtplib.SMTP(HOST, int(PORT)) | ||
server.connect(HOST, int(PORT)) | ||
server.starttls() | ||
server.login(USER, PASS) | ||
server.sendmail(USER, TO, MSG.as_string()) | ||
server.quit() | ||
|
||
#body is used to loop through the msgs list from the chat | ||
#and grab everything that was said after .body and before | ||
#.subject. | ||
def body(BODY_INDEX,SUBJECT_INDEX, msgs): | ||
i = BODY_INDEX+1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a .split? |
||
while i < SUBJECT_INDEX: | ||
if i == BODY_INDEX + 1: | ||
if msgs[i] == "\n": | ||
Body = msgs[i] | ||
BODY = msgs[i] + " " | ||
elif i == SUBJECT_INDEX - 1: | ||
BODY = BODY + msgs[i] | ||
else: | ||
if msgs[i] == "\n": | ||
Body = BODY + msgs[i] | ||
BODY = BODY + msgs[i] + " " | ||
i = i+1 | ||
return (BODY) | ||
|
||
#subject is used to loop through the msgs list from the chat | ||
#and grab everythin after .subject and before the end of the | ||
#message | ||
def subject(SUBJECT_INDEX, MAX_INDEX, msgs): | ||
i = SUBJECT_INDEX + 1 | ||
while i < MAX_INDEX: | ||
if i == SUBJECT_INDEX + 1: | ||
SUBJECT = msgs[i] + " " | ||
elif i == MAX_INDEX - 1: | ||
SUBJECT = SUBJECT + msgs[i] | ||
else: | ||
SUBJECT = SUBJECT + msgs[i] + " " | ||
i = i+1 | ||
return (SUBJECT) | ||
|
||
def run(self, incoming, methods, info): | ||
try: | ||
# if '!~' in info['prefix']: | ||
# print(info) | ||
msgs = info['args'][1:][0].split() | ||
if info['command'] == 'PRIVMSG': | ||
#makes sure the first parameter is ".mail" | ||
if msgs[0] == '.mail': | ||
TO = msgs[1] #grabs the TO email provided | ||
BODY_INDEX = msgs.index(".body") #gets index for ".body", used in body function | ||
SUBJECT_INDEX = msgs.index(".subject") #gets index for ".subject" used in body, and subject functions | ||
MAX_INDEX = len(msgs) #gets max index to know the max indexing value | ||
|
||
BODY = Plugin.body(BODY_INDEX,SUBJECT_INDEX, msgs) #fill the BODY string using the body function to extraxt the text | ||
SUBJECT = Plugin.subject(SUBJECT_INDEX, MAX_INDEX, msgs) #fill the SUBJECT string using the subject function to extract the text | ||
|
||
MSG = MIMEText(text + BODY, 'html') #sets MSG format to html, and fills in the BODY portion | ||
MSG["Subject"] = SUBJECT #Fills the MSG's subject with SUBJECT | ||
MSG["From"] = USER #Fills the From field with USER string | ||
MSG["To"] = TO #Fills the TO field with the TO string | ||
Plugin.__email(HOST, PORT, USER, PASS, TO, MSG) #Passes paramters needed to __email to be able to start up connection to SMTP server and send message | ||
|
||
except Exception as e: | ||
print('\n*error*\nwoops plugin', __file__, e, '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommended here