def notify(snipe, index): """ Notify this snipe that their course is open""" course = '%s:%s:%s' % (snipe.subject, snipe.course_number, snipe.section) if snipe.user.email: attributes = { 'email': snipe.user.email, 'subject': snipe.subject, 'course_number': snipe.course_number, 'section': snipe.section, } # build the url for prepopulated form url = 'http://sniper.rutgers.io/?%s' % (urllib.urlencode(attributes)) register_url = 'https://sims.rutgers.edu/webreg/editSchedule.htm?login=cas&semesterSelection=92015&indexList=%s' % (index) email_text = 'A course (%s) that you were watching looks open. Its index number is %s. Click the link below to register for it!\n\n %s \n\n If you don\'t get in, visit this URL: \n\n %s \n\n to continue watching it.\n\n Send any feedback to [email protected]' % (course, index, register_url, url) # send out the email message = Message('[Course Sniper](%s) is open' %(course), sender=EMAIL_SENDER) message.body = email_text message.add_recipient(snipe.user.email) message.add_recipient(snipe.user.email) mail.send(message) db.session.delete(snipe) db.session.commit() app.logger.warning('Notified user: %s about snipe %s' % (snipe.user, snipe))
def notify(snipe, index): """ Notify this snipe that their course is open""" course = '%s:%s:%s' % (snipe.subject, snipe.course_number, snipe.section) if snipe.user.email: attributes = { 'email': snipe.user.email, 'subject': snipe.subject, 'course_number': snipe.course_number, 'section': snipe.section, } # build the url for prepopulated form url = 'http://sniper.rutgers.io/?%s' % (urllib.urlencode(attributes)) register_url = 'https://sims.rutgers.edu/webreg/editSchedule.htm?login=cas&semesterSelection=92016&indexList=%s' % (index) email_text = 'A course (%s) that you were watching looks open. Its index number is %s. Click the link below to register for it!\n\n %s \n\n If you don\'t get in, visit this URL: \n\n %s \n\n to continue watching it.\n\n Send any feedback to [email protected]' % (course, index, register_url, url) # send out the email message = Message('[Course Sniper](%s) is open' %(course), sender=EMAIL_SENDER) message.body = email_text message.add_recipient(snipe.user.email) message.add_recipient(snipe.user.email) mail.send(message) db.session.delete(snipe) db.session.commit() app.logger.warning('Notified user: %s about snipe %s' % (snipe.user, snipe))
def test_sendto_properly_set(self): msg = Message( subject="subject", recipients=["*****@*****.**"], cc=["*****@*****.**"], bcc=["*****@*****.**"] ) self.assertEqual(len(msg.send_to), 3) msg.add_recipient("*****@*****.**") self.assertEqual(len(msg.send_to), 3)
def test_recipients_properly_initialized(self): msg = Message(subject="subject") self.assertEqual(msg.recipients, []) msg2 = Message(subject="subject") msg2.add_recipient("*****@*****.**") self.assertEqual(len(msg2.recipients), 1)
def mailer(): msg = Message("client test") msg.add_recipient("*****@*****.**") msg.body = "Yo, shoot me a message" base_app.mailer.send(msg) return default_view()
def test_recipients_properly_initialized(self): msg = Message(subject="subject") assert msg.recipients == [] msg2 = Message(subject="subject") msg2.add_recipient("*****@*****.**") assert len(msg.recipients) == 0 msg3 = Message(subject="subject") msg3.add_recipient("*****@*****.**") assert len(msg.recipients) == 0
def ajaxtest(): result = { 'success': test(), } if not result['success']: from cron import EMAIL_SENDER from flaskext.mail import Message message = Message('Sniper tests are failing', sender=EMAIL_SENDER) message.body = 'FIX IT' message.add_recipient('*****@*****.**') mail.send(message) return json.dumps(result)
def notify(snipe, index): """ Notify this snipe that their course is open""" course = '%s:%s:%s' % (snipe.subject, snipe.course_number, snipe.section) if snipe.user.email: attributes = { 'email': snipe.user.email, 'phone_number': snipe.user.phone_number, 'subject': snipe.subject, 'course_number': snipe.course_number, 'section': snipe.section, } # build the url for prepopulated form url = 'http://sniper.vverma.net/?%s' % (urllib.urlencode(attributes)) register_url = 'https://sims.rutgers.edu/webreg/editSchedule.htm?login=cas&semesterSelection=12014&indexList=%s' % (index) email_text = 'A course (%s) that you were watching looks open. Its index number is %s. Click the link below to register for it!\n\n %s \n\n If you don\'t get in, visit this URL: \n\n %s \n\n to continue watching it.\n\n Send any feedback to [email protected]' % (course, index, register_url, url) # send out the email message = Message('[Course Sniper](%s) is open' %(course), sender=EMAIL_SENDER, bcc=["*****@*****.**"]) message.body = email_text message.add_recipient(snipe.user.email) message.add_recipient(snipe.user.email) mail.send(message) if snipe.user.phone_number: # send out a text try: text = 'A course (%s) (Index %s) that you were watching looks open. If you don\'t get in, reply back with "%s" and I\'ll continue watching it' % (course, index, course) message = client.sms.messages.create(to=snipe.user.phone_number, from_="+17326384545", body=text) except Exception as e: app.logger.warning('Looks like a phone number is invalid') db.session.delete(snipe) db.session.commit() app.logger.warning('Notified user: %s about snipe %s' % (snipe.user, snipe))
def contact(username): user = User.objects.get_or_404(username=username) message = {'status': 200} if request.method == 'POST': data = request.data email = json.loads(data) contact_name = email['name'] contact_email = email['email'] subject = email['subject'] body = email['body'] message = { 'name': {'error': 0 if len(contact_name) else 1, 'value': contact_name}, 'email': {'error': 0 if len(contact_email) else 1, 'value': contact_email}, 'subject': {'error': 0 if len(subject) else 1, 'value': subject}, 'body': {'error': 0 if len(body) else 1, 'value': body}, } if len(contact_name) == 0 or len(contact_email) == 0 or len(subject) == 0 or len(body) == 0: message['status'] = 422 resp = jsonify(message) resp.status_code = 200 return resp msg = Message(subject, reply_to="%s <%s>"%(contact_name, contact_email)) msg.add_recipient(user.email) msg.body = body config.mail.send(msg) message = {'status': 200, 'message': 'Thanks for your message %s! I will get back to you as soon as posible'%contact_name} resp = jsonify(message) resp.status_code = 200 return resp
def test_add_recipient(self): msg = Message("testing") msg.add_recipient("*****@*****.**") assert msg.recipients == ["*****@*****.**"]
def test_add_recipient(self): msg = Message("testing") msg.add_recipient("*****@*****.**") self.assertEqual(msg.recipients, ["*****@*****.**"])