def send_mail(): # Fetch providers, and abort if there are none available providers = ProviderModel.getAllByRank() if providers is None: abort(503) # Service temporarily unavailable # Verify that all required post variables are present dataHandler = EmailDataHandler( request.form.get('email_from', ''), request.form.get('email_to', ''), request.form.get('email_subject', ''), request.form.get('email_message', '') ) # Check the posted data for errors validationErrors = dataHandler.getErrors() if validationErrors is not None: return jsonify({'status': 'error', 'reason': 'validation', 'errors': validationErrors}) # The data is valid, send emails emailSender = EmailSender(dataHandler, providers, logger=app.logger) res = emailSender.send() # Check for errors if not res['errors']: # All emails sent successfully return jsonify({'status': 'success'}) else: return jsonify({'status': 'error', 'reason': 'email', 'failed': res['errors']})
def main(): parser = ArgumentParser() parser.add_argument('--from_address', required=True, help="sender email address") parser.add_argument('--to_addresses', required=True, nargs='+', help="list of receivers email addresses") parser.add_argument('--subject', required=True, help="subject") parser.add_argument('--body', required=True, help="message body") parser.add_argument('--body_type', choices=['plain', 'html'], default='plain', help="message body type (default: %(default)s)") parser.add_argument('--attachments', nargs='*', help="list of attachments") parser.add_argument('--certificates', nargs='*', help="list of certificates") parser.add_argument('--config', default="config.ini", help="config file location") parser.add_argument('--password', help="password for email server authentication") args = parser.parse_args() conf_parser = ConfigParser({ 'host': 'localhost', 'port': 25, 'sign': False, 'Encrypt': False }) conf_args = conf_parser.read(args.config) if len(conf_args) != 1: raise FileNotFoundError("The config file does not exist") email = EmailSender(host=conf_parser.get('mail', 'host'), port=conf_parser.getint('mail', 'port'), key=conf_parser.get('mail', 'key'), cert=conf_parser.get('mail', 'cert'), sign=conf_parser.getboolean('mail', 'sign'), encrypt=conf_parser.getboolean('mail', 'encrypt')) msg = Message() msg.set_sender(args.from_address) msg.set_recipients(args.to_addresses) msg.set_subject(args.subject) msg.set_body(args.body, type=args.body_type) for attachment in args.attachments: msg.add_attachment(attachment) message = email.set_message(msg, certificates=args.certificates) print(message) email.send(message, password=args.password)
def run(self): message = self.generate_alert() details = lucario_email() build = { 'sender_address': details['sender'], 'password': details['password'], 'receiver_address': details['receiver'], 'email_subject': message['subject'], 'mail_content': message['body'] } email = EmailSender(build) email.send_email() return print('Success,Email sent')
def test_onlyUsedProvidersAreLoaded(self): receivers = ','.join(['*****@*****.**', '*****@*****.**']) dataHandler = EmailDataHandler('*****@*****.**', receivers, '', '') providerreturn = {'successes': ['*****@*****.**', '*****@*****.**'], 'errors': []} mockprovider = self.makeProviderMock(providerreturn) mockimporter = self.makeImporterMock([mockprovider]) providerModel1 = ProviderModel('name1', 'key') providerModel2 = ProviderModel('name2', 'key') sender = EmailSender(dataHandler, [providerModel1, providerModel2], importer=mockimporter) res = sender.send() self.assertEquals(len(res['successes']), 2)
def test_whenFirstProviderFailsTheSecondKicksIn(self): receivers = ','.join(['*****@*****.**', '*****@*****.**']) dataHandler = EmailDataHandler('*****@*****.**', receivers, '', '') providerreturn1 = {'successes':[], 'errors':[{'mail':'*****@*****.**','reason':''}, {'mail':'*****@*****.**','reason':''}]} providerreturn2 = {'successes':['*****@*****.**', '*****@*****.**'], 'errors':[]} mockprovider1 = self.makeProviderMock(providerreturn1) mockprovider2 = self.makeProviderMock(providerreturn2) mockimporter = self.makeImporterMock([mockprovider1, mockprovider2]) providerModel1 = ProviderModel('name1', 'key') providerModel2 = ProviderModel('name2', 'key') sender = EmailSender(dataHandler, [providerModel1, providerModel2], importer=mockimporter) res = sender.send() self.assertEquals(sender.getProviderInfo(name='name1')['errors'], 2) self.assertEquals(sender.getProviderInfo(name='name2')['successes'], 2)
def test_send(self): conf_file = 'gsm-devconfig/settings.ini' settings = gsm_lib.get_settings(conf_file) props = EmailProps(settings.smtp_host, settings.smtp_port, settings.sender_email, [settings.test_recipient], [], 'Research Subject Mapper Notification', 'This is a test') success = EmailSender().send(props) self.assertEqual(True, success)
def test_sendEmailMultipleProvidersFirstFailsSome(self): receivers = ','.join(['*****@*****.**', '*****@*****.**', '*****@*****.**']) dataHandler = EmailDataHandler('*****@*****.**', receivers, '', '') providerreturn1 = {'successes':['*****@*****.**'], 'errors':[{'mail':'*****@*****.**','reason':''}, {'mail':'*****@*****.**','reason':''}]} providerreturn2 = {'successes':['*****@*****.**', '*****@*****.**'], 'errors':[]} mockprovider1 = self.makeProviderMock(providerreturn1) mockprovider2 = self.makeProviderMock(providerreturn2) mockimporter = self.makeImporterMock([mockprovider1, mockprovider2]) providerModel1 = ProviderModel('name1', 'key') providerModel2 = ProviderModel('name2', 'key') sender = EmailSender(dataHandler, [providerModel1, providerModel2], importer=mockimporter) res = sender.send() provider1info = sender.getProviderInfo(name='name1') provider2info = sender.getProviderInfo(name='name2') self.assertEquals(provider1info['successes'], 1) self.assertEquals(provider1info['errors'], 2) self.assertEquals(provider2info['successes'], 2) self.assertEquals(provider2info['errors'], 0)
def runChecker(website,code): # log = open("log_status.txt",'a') try: connect_status = connect(website, code) #connect_status = request.get(website+code).status_code except Exception as a: print( a) return if connect_status == 200: # inf.write("working: %s | Status: %i"%( code, connect_status)) # print("working code: %s | Status: %i" %(code,connect_status)) # inf.close()i if notif not None: try: # print("HELLO") mail = EmailSender() mail.sendMessage(address,code) except Exception as e: print(e) pass #else: #print("not working: %s |Status: %i "%( code, connect_status)) #print(multiprocessing.current_process()) # print("Process ID: " + multiprocessing.current_process().name + " Not working code: " + code + " |Status: " + str(connect_status)) print("Process ID: " + multiprocessing.current_process().name + " Code: " + code + " |Status: " + str(connect_status))
def __init__(self,URL, notifyAddr, explicitKeywords = None): """URL: craigslist link including price parameters entered. notifyAddr: Passed as an list if there are 2 or more / recipiants, else accepts a stringexplicitKeywords: if / there are specific keywords to include in the title of/ the posting list them here as a list if two or more """ ##### Variables self.url = URL self.baseURL = URL[:URL.find("org")+3] # accessing substring from start of URL to end of 'org' domain self.notifyAddr = notifyAddr # address to send notifications to self.explicitKeywords = explicitKeywords #NOT implemented yet self.mailMan = EmailSender() #create the instance of EmailSender to send notifications to email #self.request = urllib.request.urlopen(self.url) #self.stack = list() self.stack = CraigslistStack()
def get_file_from_uri(self, remote_path, local_path, props=None): ''' To email exceptions the caller must pass the object `props` of type EmailProps ''' try: self.get(remote_path, local_path) except Exception, e: error = 'There was an error getting file %s from %s: %s' % ( remote_path, self._hostname, str(e)) logging.error(error) if props: # include the exception in the email body props.msg_body = error EmailSender().send(props)
def send_file_to_uri(self, remote_path, file_name, local_path, props=None): ''' To email exceptions the caller must pass the object `props` of type EmailProps ''' try: self.put(local_path, os.path.join(remote_path, file_name)) except Exception, e: error = 'There was an error sending file %s to %s: %s' % ( file_name, self._hostname, str(e)) logging.error(error) logging.error( 'Please check the credentials/remotepath/localpath/Server URI') if props: # include the exception in the email body props.msg_body = error EmailSender().send(props)
def main(): email = EmailSender(emailPropertiesFile) config = configparser.ConfigParser() config.read(emailPropertiesFile) checkTermin(email, config)
"mapreduce.fileoutputcommitter.marksuccessfuljobs", "false") log4jLogger = sc._jvm.org.apache.log4j logger = log4jLogger.LogManager.getLogger("IDDLLogger") logger.info("Ingestion started -- %s" % datetime.now()) parser = argparse.ArgumentParser() parser.add_argument("configfile", help="configuration file") parser.add_argument("filelist", help="list of data files") args = parser.parse_args() config = Config(sc, args.configfile) fileliststr = args.filelist emailsender = EmailSender(sc, config) hdfsutil = HDFSUtil(sc) try: if fileliststr: hdfsfiles = hdfsutil.getFullPathList(config, fileliststr) else: hdfsfiles = hdfsutil.listHDFSTmpFiles(config) logger.info("file_count = " + str(len(hdfsfiles))) logger.info(hdfsfiles) if len(hdfsfiles) == 0: logger.error("no file was found in hdfs tmp folder!") emailsender.send_error_email( "no file was found in hdfs tmp folder!")
# Avoid import error when running the the terminal # Add module paths outside of the current folder import sys sys.path.append(r"C:\\Users\quang\PycharmProjects\pythonProject3") from emailsender import EmailSender from API_ctsv_UIT.ctsv_api import CTSV_API from datetime import datetime import time bot = CTSV_API() email_bot = EmailSender() if bot.hasNewArticle(): new_articles = bot.getLatestArticle() email_bot.make_message_with(subject="[CSTV] Thông báo mới", plain_text=new_articles) email_bot.send_message_to()
class CraigslistBot(): """ NOTES: BUGS####################### ***********BUG DOES NOT CORRECTLY ADD THE FIRST LISTING IN IT. #Note to self, need to make sure i change the collections tructure to using a QUeue instead of a stack, #the stack does not allow me to know the first item added**** self notes**** 1)when passing s url without giving price perameters, it will crash 2)Need to add a try and catch to catch python winError 10060, connection time out and reconnect if this happens NOTES: Still needs development################ 1) """ def __init__(self,URL, notifyAddr, explicitKeywords = None): """URL: craigslist link including price parameters entered. notifyAddr: Passed as an list if there are 2 or more / recipiants, else accepts a stringexplicitKeywords: if / there are specific keywords to include in the title of/ the posting list them here as a list if two or more """ ##### Variables self.url = URL self.baseURL = URL[:URL.find("org")+3] # accessing substring from start of URL to end of 'org' domain self.notifyAddr = notifyAddr # address to send notifications to self.explicitKeywords = explicitKeywords #NOT implemented yet self.mailMan = EmailSender() #create the instance of EmailSender to send notifications to email #self.request = urllib.request.urlopen(self.url) #self.stack = list() self.stack = CraigslistStack() def __buildInitalListing(self): """ Will build a stack with the current listed postings, Creates a craiglist object, then appends them to the stack""" request = urllib.request.urlopen(self.url) bsObj = BeautifulSoup(request.read()) soup = bsObj('p', {"class": "row"}) # print(len(soup)) #searchTitle = bsObj.title.contents[0] for listing in range(0, len(soup) -1): createObj = self.__buildListingObj(bsObj,listing) # print(str(listing) + "th object to add to stack" + createObj.__str__()) # print("length" + str(len(bsObj))) self.stack.append(createObj) def __buildListingObj(self, DOM, index = 0): """Testing this method to optimize the code This method is reused whenever we need to parse the tags and create a listing Object from that imformation""" soup = DOM('p', {"class": "row"}) # finds p tags (paragraph) with attribute "class: row" attached to them timeOfListing = soup[index].find("time").contents[0] #gets the date of the listing listingLink = soup[index].find('a')["href"] #get's the href link address tot he listing listingID = soup[index]['data-pid'] #gets the postings ID this is used to identify if two post are identical or not. nameOfListing = soup[index].find('a',{"class":"hdrlnk"}).contents[0] # gets the name of the listing priceOfListing = soup[index].find("span", {"class":"price"}).contents[0] #get the price of the listing return CraigslistPostObj(nameOfListing, listingID, priceOfListing, timeOfListing, self.baseURL + listingLink) # returns an object of type CraigslistPostingObj def run(self): self.__buildInitalListing() sleepTime = 260 while(True): try: request = urllib.request.urlopen(self.url) soupGetDom = BeautifulSoup(request.read())#reads from the URL and gets the document online into DOM listingObj = self.__buildListingObj(soupGetDom)#testing!!! print("This is the current listing being checked online:"\ + listingObj.__str__()) print("\n") print("THIS IS THE CURRENT ITEM AT THE BEGINNING OF THE STACK"\ + self.stack[0].__str__()) print("\n") if(self.stack.peek().__eq__( listingObj)): print("they are the same") #emailSender.sendMessage(["*****@*****.**","*****@*****.**"], #"We have a update\n" + listingObj.__str__()) #emailSender.sendMessage(["*****@*****.**","*****@*****.**"], "same posting" + listingObj.__str__()) else: self.stack.insert(0, listingObj) # self.stack.append(listingObj) self.mailMan.sendMessage( ["*****@*****.**","*****@*****.**"], "We have a UPDATE\n" + listingObj.__str__()) print("they are NOT the same") except Exception as e: print("\n\n\n THERE WAS AN ERROR OR SOME TIMEOUT OCCURED") sleepTime = random.randint(0,sleepTime) + sleepTime self.mailMan.sendMessage(["*****@*****.**"],"WE have encountered a problem") time.sleep(sleepTime) self.mailMan.sendMessage( ["*****@*****.**","*****@*****.**"], "I'm still here and running ")
class feedbackChat: def __init__(self): """Constructor""" self.replics = Replics() self.funnel = funnelProcessor() self.textProcessor = TextProcessor() self.email = EmailSender() def new_chat(self, chat_id, message_id, text, text_raw): fb = ChatFeedback(chatuser_id=chat_id) fb.save() return fb.id def open_last_chat(self, chat_id): fb = ChatFeedback.select().where( (ChatFeedback.chatuser_id == chat_id)).order_by( ChatFeedback.id.desc()).dicts() if len(fb): fb = fb.get() return fb def update_chat(self, id, fields): # query = ChatFeedback.update(**fields).where(ChatFeedback.id == id) query = ChatFeedback.update(**fields).where(ChatFeedback.id == id) query.execute() return query def name_add(self, chat_id, message_id, text, text_raw): last_chat = self.open_last_chat(chat_id) self.update_chat(last_chat['id'], {'name': text_raw}) response = self.replics.feedback_name_confirm(chat_id, text_raw) self.funnel.set_funnel(chat_id, 'feedback_phone', '') return response def name_confirm(self, chat_id, message_id, text, text_raw): pass def phone_add(self, chat_id, message_id, text, text_raw): response = self.replics.feedback_phone(chat_id, text_raw) last_chat = self.open_last_chat(chat_id) self.update_chat(last_chat['id'], {'phone': text_raw}) self.funnel.set_funnel(chat_id, 'feedback_city', '') return response def phone_confirm(self, chat_id, message_id, text, text_raw): pass def city_add(self, chat_id, message_id, text, text_raw): last_chat = self.open_last_chat(chat_id) self.update_chat(last_chat['id'], {'location': text_raw}) response = self.replics.feedback_city(chat_id, text_raw) self.funnel.set_funnel(chat_id, 'feedback_form_confirm', '') return response def text_add(self, chat_id, message_id, text, text_raw): last_chat = self.open_last_chat(chat_id) self.update_chat(last_chat['id'], {'message': text_raw}) response = self.replics.feedback_name(chat_id, text_raw) self.funnel.set_funnel(chat_id, 'feedback_name', '') return response def city_confirm(self, chat_id, message_id, text, text_raw): pass def time_add(self, chat_id, message_id, text, text_raw): pass def time_confirm(self, chat_id, message_id, text, text_raw): pass def form_confirm(self, chat_id, message_id, text, text_raw): # last_chat = self.open_last_chat(chat_id) # self.update_chat(last_chat['id'], {'location':text_raw}) sentiment = self.textProcessor.define_positive(text_raw) if sentiment == 1: response = self.replics.feedback_confirm(chat_id) self.funnel.set_funnel(chat_id, 'drop', '') else: response = self.replics.feedback_cancel(chat_id) self.funnel.set_funnel(chat_id, 'drop', '') self.send_email(chat_id) return response def get_username(self, chat_id): fb = ChatUser.select().where((ChatUser.id == chat_id)).get() if fb.username: un = '(ник: @{})'.format(fb.username) else: un = '' return un def send_email(self, chat_id): last_chat = self.open_last_chat(chat_id) username = self.get_username(chat_id) message = 'Клиент: {} {}\n\nГород: {}\n\nТелефон: {}\n\nСообщение: {}'.format( last_chat['name'], username, last_chat['location'], last_chat['phone'], last_chat['message']) self.email.send_email(message) return 1
def __init__(self): """Constructor""" self.replics = Replics() self.funnel = funnelProcessor() self.textProcessor = TextProcessor() self.email = EmailSender()
from utils import make_password, check_password import random from emailsender import EmailSender import os from event.models import Event from event.api.serializer import EventSerializer from .swaggerresponse import PostCredentialUser, AttendEventParams, \ UpdatePasswordParams, ForgetPasswordParams, UserUpdateParams,\ UserLoginParams, UserRegisterParmas, UserRetriveUsername from drf_yasg.utils import swagger_auto_schema from drf_yasg import openapi key = os.environ.get('key') temp = {} sender = EmailSender.instance(key) class UserRegisterView(APIView): user_response = openapi.Response('return credential of user', UserSerializer) @swagger_auto_schema(request_body=UserRegisterParmas, responses={ 200: user_response, 403: '"status": "Username/email Already Exist"' }) def post(self, request): # print(request.body.decode('utf-8')) post_data = json.loads(request.body.decode('utf-8')) data = User.objects.filter(email=post_data['email']).all()
job_extractor = JobExtractor( f'{Constants.URL_TEMPLATE.value}&page={page_number}') job_extractor.start_driver() job_extractor.load_page() page_posts = job_extractor.extract_data( job_extractor.filtered_posts( job_extractor.is_recent(['today', 'yesterday', '2 days', '3 days']))) total_posts = list(page_posts) while len(page_posts) != 0: page_number += 1 job_extractor.set_url(f'{Constants.URL_TEMPLATE.value}&page={page_number}') job_extractor.load_page() page_posts = job_extractor.extract_data( job_extractor.filtered_posts( job_extractor.is_recent(['today', 'yesterday', '2 days', '3 days']))) total_posts += page_posts jobs_dumper = JobsDumper('jobs.csv') jobs_dumper.dump(total_posts) email_generator = EmailContentGenerator() email = email_generator.dump(total_posts) sender = EmailSender() sender.send(email) job_extractor.close_driver()