|
| 1 | +import smtplib, ssl |
| 2 | +import sys |
| 3 | +from email.mime.text import MIMEText |
| 4 | +from email.mime.multipart import MIMEMultipart |
| 5 | + |
| 6 | +sys.path.append('<path botnet root dir>') |
| 7 | +import config |
| 8 | + |
| 9 | + |
| 10 | +def send_email(receiver_email, subject, plain_text, html): |
| 11 | + sender_email = "<your_email_domain>" |
| 12 | + password = config.email_password |
| 13 | + |
| 14 | + message = MIMEMultipart("alternative") |
| 15 | + message["Subject"] = subject |
| 16 | + message["From"] = sender_email |
| 17 | + message["To"] = receiver_email |
| 18 | + |
| 19 | + # Create the plain-text and HTML version of your message |
| 20 | + # text = """\ |
| 21 | + # Hi, |
| 22 | + # How are you? |
| 23 | + # Real Python has many great tutorials: |
| 24 | + # www.realpython.com""" |
| 25 | + # html = """\ |
| 26 | + # <html> |
| 27 | + # <body> |
| 28 | + # <p>Hi,<br> |
| 29 | + # How are you?<br> |
| 30 | + # <a href="http://www.realpython.com">Real Python</a> |
| 31 | + # has many great tutorials. |
| 32 | + # </p> |
| 33 | + # </body> |
| 34 | + # </html> |
| 35 | + # """ |
| 36 | + |
| 37 | + # Turn these into plain/html MIMEText objects |
| 38 | + part1 = MIMEText(plain_text, "plain") |
| 39 | + part2 = MIMEText(html, "html") |
| 40 | + |
| 41 | + # Add HTML/plain-text parts to MIMEMultipart message |
| 42 | + # The email client will try to render the last part first |
| 43 | + message.attach(part1) |
| 44 | + message.attach(part2) |
| 45 | + |
| 46 | + # Create secure connection with server and send email |
| 47 | + context = ssl.create_default_context() |
| 48 | + with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server: |
| 49 | + server.login(sender_email, password) |
| 50 | + server.sendmail( |
| 51 | + sender_email, receiver_email, message.as_string() |
| 52 | + ) |
| 53 | + return 1 |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + import json |
| 59 | + with open(r"/botnet/CC/email.json") as f: |
| 60 | + f_d = json.load(f) |
| 61 | + |
| 62 | + send_email("<receiver>", f_d["subject"], f_d["plaintext"], f_d["html"]) |
0 commit comments