Commit 9c83c685 authored by kaiyou's avatar kaiyou

Generate fake email content to avoid antispam

parent c8b645a4
Pipeline #260 passed with stage
in 1 minute and 52 seconds
......@@ -2,6 +2,7 @@ import imaplib
import smtplib
import os
import time
import faker
from email.mime import text, multipart
......@@ -41,16 +42,18 @@ def imap_login(context, host, username, password, port=143, encrypt=None):
def send_mail(context, account, to, message):
""" Send a message to the given account
"""
fake = faker.Faker()
smtp = get_smtp_client(
account["host"], account.get("port", 587),
account.get("encrypt", None)
)
smtp.login(account["username"], account["password"])
mail = multipart.MIMEMultipart("alternative")
mail["Subject"] = f"Monitoring canary {message}"
mail["Subject"] = fake.sentence(nb_words=6, variable_nb_words=True)
mail["Subject"] += message
mail["From"] = account["username"]
mail["To"] = to
mail.attach(text.MIMEText("Simple monitoring!", "text"))
mail.attach(text.MIMEText("\n".join(fake.paragraphbs(nb=5)), "text"))
smtp.sendmail(account["username"], to, mail.as_string())
smtp.quit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment