Skip to content

Commit

Permalink
Version 1.0.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
shvuuuu committed Aug 15, 2023
1 parent 5259492 commit e2cf476
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
3 changes: 2 additions & 1 deletion mailpad/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .mail import mailpad
from .mailAI import mailpadAI

__all__ = ["mailpad"]
__all__ = ["mailpad", "mailpadAI"]
38 changes: 11 additions & 27 deletions mailpad/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,20 @@
from email.mime.application import MIMEApplication
import os

class mailpad:
default_smtp_server = 'smtp-relay.brevo.com'
default_smtp_port = 587

@classmethod
def brevo(cls):
cls.default_smtp_server = 'smtp-relay.brevo.com'
cls.default_smtp_port = 587
smtp_email = os.environ.get('MAILPAD_EMAIL')
smtp_password = os.environ.get('MAILPAD_PASSWORD')

def __init__(self, smtp_server=None, smtp_port=None, smtp_email=None, smtp_password=None):
class mailpad:
def __init__(self, smtp_server=None, smtp_port=None):
self.smtp_server=smtp_server
self.smtp_port=smtp_port
self.context = ssl.create_default_context()

if smtp_server is None and smtp_port is None:
self.smtp_server = mailpad.default_smtp_server
self.smtp_port = mailpad.default_smtp_port
else:
self.smtp_server = smtp_server
self.smtp_port = smtp_port

# Automatically fetch SMTP email and password from environment variables
self.smtp_email = os.environ.get('MAILPAD_EMAIL') if smtp_email is None else smtp_email
self.smtp_password = os.environ.get('MAILPAD_PASSWORD') if smtp_password is None else smtp_password

def brevo(self):
self.smtp_server = 'smtp-relay.brevo.com'
self.smtp_port = 587

def send_mail(self, from_email, to_email, subject, message):
if not self.smtp_email or not self.smtp_password:
raise ValueError("Email user or password not set.")

msg = MIMEMultipart()
msg['From'] = from_email
Expand All @@ -46,19 +34,15 @@ def send_mail(self, from_email, to_email, subject, message):
print(f"Mail sent to - {to_email}")

def send_mail_with_attachment(self, from_email, to_email, subject, message, attachment_path):
if not self.smtp_email or not self.smtp_password:
raise ValueError("Email user or password not set.")


msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = ', '.join(to_email)
msg['Subject'] = subject

# Attach the message body
part = MIMEText(message)
msg.attach(part)

# Attach the file
with open(attachment_path, 'rb') as f:
part = MIMEApplication(f.read())
part.add_header('Content-Disposition', 'attachment; filename="' + attachment_path.split('/')[-1] + '"')
Expand Down
37 changes: 37 additions & 0 deletions mailpad/mailAI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI

class mailpadAI:
def __init__(self):
self.openai_llm = None
self.default_openai_config = {"temperature": 0.9, "model": "text-davinci-003"}

def openai(self, temperature=None, model=None):
if temperature is None:
temperature = self.default_openai_config["temperature"]
if model is None:
model = self.default_openai_config["model"]

self.openai_llm = OpenAI(temperature=temperature, model=model)

def get_llm_response(self, form_input, email_sender, email_recipient, email_style):
llm = self.openai_llm
if llm is None:
raise ValueError("LLM model not initialized.")

template = """
Write an email with {style} style and includes topic: {email_topic}.
\nSender: {sender}
Recipient: {recipient}
\nEmail Text:
"""

prompt = PromptTemplate(
input_variables=["style", "email_topic", "sender", "recipient"],
template=template,
)

response = llm(prompt.format(email_topic=form_input, sender=email_sender, recipient=email_recipient, style=email_style))
return response

__all__ = ['mailpadAI']
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from setuptools import setup, find_packages

VERSION = '0.1.2'
VERSION = '1.0.0'
DESCRIPTION = 'Python Mailing Library'
LONG_DESCRIPTION = 'A package that allows to send mails from python environment'

# Setting up
setup(
name="mailpad",
version=VERSION,
Expand All @@ -14,6 +13,7 @@
long_description_content_type="text/markdown",
long_description=LONG_DESCRIPTION,
packages=find_packages(),
install_requires=['langchain'],
keywords=['mailpad','python', 'mail', 'email', 'email client', 'smtp'],
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down

0 comments on commit e2cf476

Please sign in to comment.