Created
November 7, 2021 01:27
-
-
Save lachlan2k/22f0f791dd710a4e3ba940e2a4d76321 to your computer and use it in GitHub Desktop.
Relay iLO4 AlertMail to a Discord Webhook with a simple SMTP server
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
import email | |
import asyncio | |
import requests | |
import quopri | |
from aiosmtpd.controller import Controller | |
from email.policy import default as default_policy | |
# Closest thing to auth it supports, just use a random long string as the recipient | |
KEY = '<snip>@foobar.com' | |
WEBHOOK_URL = 'https://discord.com/api/webhooks/<snip>' | |
# Your discord ID so it can ping you | |
DISCORD_ID = '<snip>' | |
PORT = 9999 | |
class ILOBoiHandler: | |
async def handle_DATA(self, server, session, envelope): | |
msg = email.message_from_bytes(envelope.content, policy=default_policy) | |
if msg.get('To') != KEY: | |
return print('Email received with wrong key') | |
discord_message = f"<@{DISCORD_ID}>\n```\nSubject: {msg.get('Subject')}\n\n{msg.get_content()}```" | |
requests.post(WEBHOOK_URL, json={ 'content': discord_message, 'username': 'Mr. ILO' }) | |
return '250 OK' | |
handler = ILOBoiHandler() | |
controller = Controller(handler, hostname='0.0.0.0', port=PORT) | |
controller.start() | |
input('Starting SMTP ILO Webhook Relay Extreme Pro') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example received notification: