Пример #1
0
def SendMail(sender = None , to = None, cc = None, subject = None, body = '' ):
	"""
	Sends Emails loads login and server information from config.ini.
	Args:
		sender:
		to:
		cc:
		subject:
		body:

	Returns:
	Exceptions:
	SMTPException
	"""
	
	emailinfo = read_config(section='Email_Login')
	emailserver = read_config(section='Email_Server')

	try:
		Log.info(('EMAIL:', 'Attempting to connect to email server'))
		session = smtplib.SMTP(**emailserver)
		session.ehlo()
		session.starttls()
		session.login(**emailinfo)
		Log.info(('EMAIL:', 'Successfully connected to email server'))

		Log.info(('EMAIL:', 'Trying to send an email'))
		headers = "\r\n".join(["from: " + sender,
									 "subject: " + subject,
									 "to: " + to,
									 "mime-version: 1.0",
									 "content-type: text/html"])
		content = headers + "\r\n\r\n" + body
		session.sendmail(sender, to, content)
		Log.info(('EMAIL:', 'Successfully sent email'))
	except SMTPException as e:
		Log.error(('EMAIL:', e))
		Log.info('EMAIL:PARAMS:',sender, to, content)
		Log.info('EMAIL:', 'Failed to send email')
Пример #2
0
def SendMail(sender=None, to=None, cc=None, subject=None, body=''):
    """
	Sends Emails loads login and server information from config.ini.
	Args:
		sender:
		to:
		cc:
		subject:
		body:

	Returns:
	Exceptions:
	SMTPException
	"""

    emailinfo = read_config(section='Email_Login')
    emailserver = read_config(section='Email_Server')

    try:
        Log.info(('EMAIL:', 'Attempting to connect to email server'))
        session = smtplib.SMTP(**emailserver)
        session.ehlo()
        session.starttls()
        session.login(**emailinfo)
        Log.info(('EMAIL:', 'Successfully connected to email server'))

        Log.info(('EMAIL:', 'Trying to send an email'))
        headers = "\r\n".join([
            "from: " + sender, "subject: " + subject, "to: " + to,
            "mime-version: 1.0", "content-type: text/html"
        ])
        content = headers + "\r\n\r\n" + body
        session.sendmail(sender, to, content)
        Log.info(('EMAIL:', 'Successfully sent email'))
    except SMTPException as e:
        Log.error(('EMAIL:', e))
        Log.info('EMAIL:PARAMS:', sender, to, content)
        Log.info('EMAIL:', 'Failed to send email')
Пример #3
0
import mysql.connector
import logging
from mysql.connector import Error
from Config import read_config
from Log import Log

# Datbase Connection/Cursor Configuration
### TODO: Move these out to an ini file, and have them being server-specific settings.
defaultConnectionParams = read_config(section='mysql')

defaultCursorParams = {"dictionary": True}


class Database:
    """
	Convenience class for dealing with a common database connection.	You can just import the db variable into your
	code and you'll have an open connection and cursor ready to use.

	Example:
		
		from Database import db
		db.cursor.execute( "SELECT * FROM table_name;" )
	"""
    connection = None
    cursor = None

    def FetchByID(self, table_name, id, id_field='id'):
        """
		Generic function to fetch a single row from database using simple WHERE id_field = id query
		Args:
		    table_name:
Пример #4
0
import logging
from Config import read_config

loggingConfig = read_config(section="logging")
loggingDict = {"NOTSET": 0, "DEBUG": 10, "INFO": 20, "WARNING": 30, "ERROR": 40, "CRITICAL": 50}
logging.basicConfig(format="%(asctime)s %(name)-6s %(levelname)-8s %(message)s", **loggingConfig)

formatter = logging.Formatter("%(name)-2s: %(levelname)-2s %(message)s")
console = logging.StreamHandler()
console.setLevel(logging.ERROR)
console.setFormatter(formatter)

logging.getLogger("").addHandler(console)  # This is the root logger

Log = logging
Пример #5
0
import logging
from Config import read_config

loggingConfig = read_config(section='logging')
loggingDict = {
    'NOTSET': 0,
    'DEBUG': 10,
    'INFO': 20,
    'WARNING': 30,
    'ERROR': 40,
    'CRITICAL': 50
}
logging.basicConfig(
    format='%(asctime)s %(name)-6s %(levelname)-8s %(message)s',
    **loggingConfig)

formatter = logging.Formatter('%(name)-2s: %(levelname)-2s %(message)s')
console = logging.StreamHandler()
console.setLevel(logging.ERROR)
console.setFormatter(formatter)

logging.getLogger('').addHandler(console)  #This is the root logger

Log = logging
Пример #6
0
import mysql.connector
import logging
from mysql.connector import Error
from Config import read_config
from Log import Log

# Datbase Connection/Cursor Configuration
### TODO: Move these out to an ini file, and have them being server-specific settings.
defaultConnectionParams = read_config(section='mysql')

defaultCursorParams = {
	"dictionary": True
}


class Database:
	"""
	Convenience class for dealing with a common database connection.	You can just import the db variable into your
	code and you'll have an open connection and cursor ready to use.

	Example:
		
		from Database import db
		db.cursor.execute( "SELECT * FROM table_name;" )
	"""
	connection = None
	cursor = None

	def FetchByID(self,table_name,id,id_field='id'):
		"""
		Generic function to fetch a single row from database using simple WHERE id_field = id query