diff --git a/open-webui-send-email.py b/open-webui-send-email.py index ac5fc84..8e63514 100644 --- a/open-webui-send-email.py +++ b/open-webui-send-email.py @@ -1,7 +1,7 @@ """ title: Send Email author: Josh Knapp -version: 0.1.0 +version: 0.2.0 description="Send email via SMTP to user specificed address" """ @@ -51,6 +51,10 @@ class Tools: default="", description="Email address to CC on all outgoing emails" ) + DEBUG: bool = Field( + default=False, + description="Debug the output of the script, defaults to False" + ) def __init__(self): self.valves = self.Valves() @@ -78,7 +82,7 @@ class Tools: msg['Subject'] = subject # Add body to email - msg.attach(MIMEText(message, 'plain')) + msg.attach(MIMEText(message + "\n\n This email was sent via OpenWebUI-SendEmail - https://repo.anhonesthost.net/OpenWebUI-Tools/OpenWebUI-SendEmail", 'plain')) # Create SMTP connection if self.valves.MAIL_SERVER_SSL: @@ -96,16 +100,27 @@ class Tools: server.login(self.valves.EMAIL_ADDRESS, self.valves.EMAIL_PASSWORD) # Send email - text = msg.as_string() + "\n\n This email was sent via OpenWebUI-SendEmail" - server.sendmail(self.valves.EMAIL_ADDRESS, to_address, text) + text = msg.as_string() + if self.valves.DEBUG: + print(f"Sending email to {to_address} with subject: {subject}") + print(f"Message content: {message}") + print(f"Using server: {self.valves.MAIL_SERVER_ADDR}:{self.valves.MAIL_SERVER_PORT}") + print(f"Using SSL: {self.valves.MAIL_SERVER_SSL}") + print(f"Using credentials: {self.valves.EMAIL_ADDRESS}") + recipients = [to_address] + if self.valves.CC_EMAIL: + recipients.append(self.valves.CC_EMAIL) + server.sendmail(self.valves.EMAIL_ADDRESS, recipients, text) server.quit() return { "success": True, - "message": f"Email sent successfully to {to_address}" + "message": f"Email sent successfully to {to_address} with CC to {self.valves.CC_EMAIL if self.valves.CC_EMAIL else 'no one'}" } except Exception as e: + if self.valves.DEBUG: + print(f"Error sending email: {str(e)}") return { "success": False, "message": f"Failed to send email: {str(e)}"