Skip to content

Commit

Permalink
Merge 9bdeb35 into 1d9b82e
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya274 committed Oct 2, 2019
2 parents 1d9b82e + 9bdeb35 commit 6306a71
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pastepwn/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
from .genericaction import GenericAction
from .databaseaction import DatabaseAction
from .savejsonaction import SaveJSONAction
from .emailaction import EmailAction

__all__ = ('BasicAction', 'SaveFileAction', 'TelegramAction', 'LogAction', 'GenericAction', 'DatabaseAction', 'SaveJSONAction')
__all__ = ('BasicAction', 'SaveFileAction', 'TelegramAction', 'LogAction', 'GenericAction', 'DatabaseAction', 'SaveJSONAction', 'EmailAction')
41 changes: 41 additions & 0 deletions pastepwn/actions/emailaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from .basicaction import BasicAction
import smtplib
import re
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

class EmailAction(BasicAction):
"""This action takes a username, password, receiver mail address,
hostname, port and when executed sends out a an
e-mail to the receiver containing the paste."""

name = "EmailAction"

def __init__(self, username, password, receiver, hostname, port):
super().__init__()
if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", username) or username is None:
raise ValueError('Invalid username !')
else:
self.username = username
if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", receiver) or receiver is None:
raise ValueError('Invalid reciever address !')
else:
self.receiver = receiver
self.password = password
self.hostname = hostname
self.port = port

def perform(self, paste):
email = MIMEMultipart()
email['From'] = self.username
email['To'] = self.receiver
email['Subject'] = 'Paste sent from pastepwn'
email.attach(MIMEText(paste, 'plain'))
session = smtplib.SMTP(self.hostname, self.port)
session.starttls()
session.login(self.username, self.password)
text = email.as_string()
session.sendmail(self.username, self.receiver, text)
session.quit()
print('Email sent to {0}'.format(self.receiver))

0 comments on commit 6306a71

Please sign in to comment.