Mini Shell

Direktori : /proc/self/root/opt/sharedrads/oldrads/mailers/
Upload File :
Current File : //proc/self/root/opt/sharedrads/oldrads/mailers/diskmovemailer.py

#!/opt/imh-python/bin/python3
"""Copyright 2011 Erik Soroka - InMotion Hosting, Inc. - e@inmotion.net - ext 834
This script connects to an SMTP server using smtplib and sends in disk move tickets
"""

# libs and other stuff we need
import sys

from smtplib import SMTP
import datetime

# smtp debug level, raise for more verbosity
debuglevel = 0

# lets make sure we received the necessary arguments

if len(sys.argv) < 2:
    print(
        '\nThis script connects to an SMTP server using python\'s smtplib and sends in'
    )
    print(
        'disk move tickets. The message body must be passed through a pipe/stdin.\n'
    )
    print("Usage:    cat filename |", sys.argv[0], "<username> <server>\n")
    sys.exit(1)

# setup smtp server info/credentials
smtp = SMTP()
smtp.set_debuglevel(debuglevel)
smtp.connect('mail.imhadmin.net', 25)
smtp.login('lamar@imhadmin.net', 'QMgg-B+W35fL')

# lets set variables based on arguments passed to us
USERNAME = sys.argv[1]
SERVER = sys.argv[2]

# where our mail should come from
from_addr = "IMH T3 Disk Management <no-replies@imhadmin.net>"

# assign to addr from powerpanel result
to_addr = "moves@imhadmin.net"

# our subject
subj = "DISK MOVE: " + USERNAME + " @ " + SERVER

# fetch the date
date = datetime.datetime.now().strftime("%m/%d/%Y %H:%M")

# get the message from stdin
message_text = sys.stdin.read()

# send it
msg = "From: {}\nTo: {}\nSubject: {}\nDate: {}\n\n{}".format(
    from_addr,
    to_addr,
    subj,
    date,
    message_text,
)
smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()

# EOF

Zerion Mini Shell 1.0