All pastes #46101 Raw Edit

Untitled

public text v1 · immutable
#46101 ·published 2006-03-18 06:20 UTC
rendered paste body
#!/usr/bin/python

# dclug bug reporting software
# input is read from the commandline and then and email is sent to support@dclug.org

import posix
import time
import smtplib

class email:
	subject = ""
	message = ""
	recipient = "support@dclug.org"
	def __init__(self):
		self.sender = posix.getlogin() + "@dclug.org"
		
	def sendrequest(self):
		# self.time contains current time AND date
		self.time = time.ctime(time.time())
		self.send = smtplib.SMTP("localhost")
		self.email = "From: " + self.sender + "\nTo: " + self.recipient + "\nSubject: " + self.subject + "\nAt " + self.time + ", " + self.sender + "sent a request for support from dclug staff. The sent message is as follows:\n\n" + self.message
		# smtplib.sendmail returns an empty dict when it is successful for some reason, hence the '== {}'
		if self.send.sendmail(self.sender, self.recipient, self.email) == {}:
			return 1
		else:
			return 0
		
		
def main():
	support = email()
	print "This is the dclug.org support request tool. With it, you can send off an official request for support to the dclug staff."
	print "What dclug feature is this support request regarding?"
	support.subject = raw_input(": ")
	print "\nPlease provide a detailed account of the problem you are encountering. If it is an always reproducable problem please include instructions for replicating the problem. Do NOT hit the enter key until you have finished explaining your problem"
	support.message = raw_input(": ")
	print "\nSend the message? (y/n)"
	action = raw_input(": ")
	if action.lower() == "y":
		if support.sendrequest():
			print "Support request sent successfully"
		else:
			print "Message sending failed, please try again later"
	else:
		print "exiting..."
	
main()