def register_complete(): from flask.ext.security import current_user from main import send_email send_email(current_user.email, "Welcome to HOUT", """Dear User: Your email account has been approved. You can now visit http://www.h-out.com/ and sign in using your Account to access new features. Please let us know if you have any questions. The HOUT Team """) return login_required_page()
def register_complete(): from flask.ext.security import current_user from main import send_email send_email( current_user.email, "Welcome to HOUT", """Dear User: Your email account has been approved. You can now visit http://www.h-out.com/ and sign in using your Account to access new features. Please let us know if you have any questions. The HOUT Team """) return login_required_page()
def send(recipent, content, sub, cc, bcc, emails): global attach_list recipent = recipent.get() content = content.get("1.0", "end-1c") subject = sub.get() cc = cc.get() bcc = bcc.get() sender = emails.get() # check_emails = [recipent, sender] # opt_emails = [cc, bcc] err = 0 if (recipent == "" or content == ""): messagebox.showerror( "Error", "One or More Essential Text Fields are Blank!") err += 1 # for email in check_emails: # if (re.search("^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$", email) == False): # messagebox.showerror("Error", "Email Format is Not Correct") # err += 1 # break # for email in opt_emails: # if (email != ""): # if (re.search("^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$", email) == False): # messagebox.showerror("Error", "Email Format is Not Correct") # err += 1 # break if (err == 0): flag = main.send_email(recipent, subject, content, sender, cc, bcc, attach_list) if flag: messagebox.showinfo("Success","The email has been sent successfully") elif flag==False: messagebox.showerror("Error","Some eroor occured, try again!")
def test_send_email(self, SMTP_SSL_mock): from settings import SENDER_SMTP_ADDRESS, SENDER_EMAIL_SMTP_PORT, SENDER_EMAIL, SENDER_EMAIL_PASSWORD login_mock = MagicMock() send_email_mock = MagicMock() smtp_connection_mock = MagicMock(login=login_mock, sendmail=send_email_mock) SMTP_SSL_mock.return_value = smtp_connection_mock send_email() # Assert it tries to establish a connection SMTP_SSL_mock.assert_called_once_with(SENDER_SMTP_ADDRESS, SENDER_EMAIL_SMTP_PORT) # assert it tries to log in login_mock.assert_called_once_with(SENDER_EMAIL, SENDER_EMAIL_PASSWORD) # assert it tries to send the email send_email_mock.assert_called_once()
def add_data(): if request.method == 'GET': return render_template('add.html', data=CURRENT_DATA) elif request.method == 'POST': if 'Add' in request.form: CURRENT_DATA['transactions'].append([ request.form.get('Description'), format_price(request.form.get('Price')), int(request.form.get('Amount')), ]) return render_template('add.html', data=CURRENT_DATA) elif 'Generate' in request.form: print(CURRENT_DATA) generate_invoice(CURRENT_DATA['name'], CURRENT_DATA['email'], CURRENT_DATA['address'], CURRENT_DATA['transactions']) send_email(CURRENT_DATA['email'], CURRENT_DATA['name']) flash("This is a test.") return redirect(url_for('main'))
def test_send_email(_sender = None, _message = None): from main import send_email return send_email(str(_sender), "Test Email Feature", """Dear User: Your email account has been approved. You can now visit http://www.h-out.com/ and sign in using your Account to access new features. Please let us know if you have any questions. The HOUT Team """)
def test_send_email(_sender=None, _message=None): from main import send_email return send_email( str(_sender), "Test Email Feature", """Dear User: Your email account has been approved. You can now visit http://www.h-out.com/ and sign in using your Account to access new features. Please let us know if you have any questions. The HOUT Team """)
def test_send_email_google_cloud_secret_manager(mock_request): secret_payload = SecretPayload( data=os.environ["NOTIFY_API_KEY"].encode("UTF-8")) access_secret_version_response = AccessSecretVersionResponse( payload=secret_payload) del os.environ["NOTIFY_API_KEY"] with mock.patch("google.auth.default", return_value=("", "project_id"), autospec=True): with mock.patch( "google.cloud.secretmanager.SecretManagerServiceClient.access_secret_version", return_value=access_secret_version_response, autospec=True, ): reload(main) responses.add(responses.POST, url, json={"content": "ok"}, status=200) response = send_email(mock_request) assert response == ("notify request successful", 200)
def test_no_valid_template_selected(mock_request): mock_request.json["payload"]["fulfilmentRequest"]["form_type"] = "not-valid" response = send_email(mock_request) assert response == ("no template id selected", 422)
def eventmatch_SMSAccpet(): from main import send_email _eventid = request.json['eventId'] _requesterid = request.json['reqUserId'] _hostid = request.json['hostId'] doc1 = ProfileModel.objects.get(userID=_requesterid) doc2 = ProfileModel.objects.get(userID=_hostid) doc3 = EventModel.objects.get(id=_eventid) requser = User.objects.get(id=_requesterid) hostuser = User.objects.get(id=_hostid) reqmessage = """Dear %(UserName)s: Your Event request: %(EventTitle)s with %(HostName)s is accepted. You will be meeting at %(EventLoc)s. %(EventTime)s Enjoy! The HOUT Team """ % { "UserName": doc1.name, "EventTitle": doc3.title, "HostName": doc2.name, "EventLoc": doc3.location, "EventTime": doc3.startTime } # "Dear "+ doc1.name +":\n\n\tYour Event Request: " + doc3.title + " With " + doc2.name + # " is accepted. You will be meeting at " + doc3.location # + ". "+ doc3.startTime + "\n\n\tEnjoy!\n\n\tThe HOUT Team" # hostmessage = "Dear "+ doc2.name +":\n\n\tYour Event: " + doc3.title + " With " + doc1.name + # " is confirmed. You will be meeting at " + doc3.location # + ". "+ doc3.startTime + "\n\n\tEnjoy!\n\n\tThe HOUT Team" hostmessage = """Dear %(HostName)s: Your Event: %(EventTitle)s with %(ReqName)s is confirmed. You will be meeting at %(EventLoc)s. %(EventTime)s Enjoy! The HOUT Team """ % { "HostName": doc2.name, "EventTitle": doc3.title, "ReqName": doc1.name, "EventLoc": doc3.location, "EventTime": doc3.startTime } send_email(requser.email, "HOUT: Your event request is accepted", reqmessage) send_email(hostuser.email, "HOUT: Your event is confirmed", hostmessage) ACCOUNT_SID = "AC7be7eca91ee23111d924d090a70fa933" AUTH_TOKEN = "c78ca17ad1777ca6de9d3f3844dbc1e6" client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) try: # To the reqeuster client.messages.create( to=doc1.phone, from_="+12036803816", body="Your Event Request: " + doc3.title + " With " + doc2.name + " is accepted. You will be meeting at " + doc3.location + ". " + doc3.startTime + " HOUT TEAM MESSAGE") client.messages.create( to=doc2.phone, from_="+12036803816", body="Your Event: " + doc3.title + " With " + doc1.name + " is confirmed. You will be meeting at " + doc3.location + ". " + doc3.startTime + " -- HOUT TEAM MESSAGE") # To the Host return 'Message Sent' except Exception, e: return str(e)
def test_missing_email_address(mock_request): del mock_request.json["payload"]["fulfilmentRequest"]["email_address"] response = send_email(mock_request) assert response == ("missing email_address identifier(s)", 422)
def test_missing_region_code(mock_request): del mock_request.json["payload"]["fulfilmentRequest"]["region_code"] response = send_email(mock_request) assert response == ("missing region_code identifier(s)", 422)
def test_missing_form_type(mock_request): del mock_request.json["payload"]["fulfilmentRequest"]["form_type"] response = send_email(mock_request) assert response == ("missing form_type identifier(s)", 422)
def test_send_email(mock_request): responses.add(responses.POST, url, json={"content": "ok"}, status=200) response = send_email(mock_request) assert response == ("notify request successful", 200)
def test_notify_response_json_decode_error(mock_request): # This shouldn't ever happen as it isn't a valid Notify response responses.add(responses.POST, url, status=200) response = send_email(mock_request) assert response == ("notify JSON response object failed decoding", 500)
def test_notify_response_no_content_204(mock_request): responses.add(responses.POST, url, json={}, status=204) response = send_email(mock_request) assert response == ("no content", 204)
def test_notify_response_error_returns_correctly(mock_request): responses.add(responses.POST, url, json={"errors": "403"}, status=403) response = send_email(mock_request) assert response == ("notify request failed", 403)
def test_missing_data_returns_422(): request = Mock(method="POST", json={}) response = send_email(request) assert response == ("missing notification request data", 422)
def test_get_not_allowed(): request = Mock(method="GET") response = send_email(request) assert response == ("method not allowed", 405)
def eventmatch_SMSAccpet(): from main import send_email _eventid = request.json['eventId'] _requesterid = request.json['reqUserId'] _hostid = request.json['hostId'] doc1 = ProfileModel.objects.get(userID = _requesterid) doc2 = ProfileModel.objects.get(userID = _hostid) doc3 = EventModel.objects.get(id=_eventid) requser = User.objects.get(id=_requesterid) hostuser = User.objects.get(id=_hostid) reqmessage = """Dear %(UserName)s: Your Event request: %(EventTitle)s with %(HostName)s is accepted. You will be meeting at %(EventLoc)s. %(EventTime)s Enjoy! The HOUT Team """ % {"UserName": doc1.name, "EventTitle": doc3.title, "HostName": doc2.name, "EventLoc": doc3.location, "EventTime": doc3.startTime} # "Dear "+ doc1.name +":\n\n\tYour Event Request: " + doc3.title + " With " + doc2.name + # " is accepted. You will be meeting at " + doc3.location # + ". "+ doc3.startTime + "\n\n\tEnjoy!\n\n\tThe HOUT Team" # hostmessage = "Dear "+ doc2.name +":\n\n\tYour Event: " + doc3.title + " With " + doc1.name + # " is confirmed. You will be meeting at " + doc3.location # + ". "+ doc3.startTime + "\n\n\tEnjoy!\n\n\tThe HOUT Team" hostmessage = """Dear %(HostName)s: Your Event: %(EventTitle)s with %(ReqName)s is confirmed. You will be meeting at %(EventLoc)s. %(EventTime)s Enjoy! The HOUT Team """ % {"HostName": doc2.name, "EventTitle": doc3.title, "ReqName": doc1.name, "EventLoc": doc3.location, "EventTime": doc3.startTime} send_email(requser.email, "HOUT: Your event request is accepted", reqmessage) send_email(hostuser.email, "HOUT: Your event is confirmed", hostmessage) ACCOUNT_SID = "AC7be7eca91ee23111d924d090a70fa933" AUTH_TOKEN = "c78ca17ad1777ca6de9d3f3844dbc1e6" client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) try: # To the reqeuster client.messages.create( to=doc1.phone, from_="+12036803816", body="Your Event Request: " + doc3.title + " With " + doc2.name + " is accepted. You will be meeting at " + doc3.location + ". "+ doc3.startTime + " HOUT TEAM MESSAGE" ) client.messages.create( to=doc2.phone, from_="+12036803816", body="Your Event: " + doc3.title + " With " + doc1.name + " is confirmed. You will be meeting at " + doc3.location + ". "+ doc3.startTime+ " -- HOUT TEAM MESSAGE" ) # To the Host return 'Message Sent' except Exception,e: return str(e)
last = datetime.datetime(int(y1[2]), int(y1[1]), int(y1[0]), int(y2[0]), int(y2[1])) if now > last: table_data.append([b[i], a[i]]) else: table_data.append([b[i], a[i]]) f.close() else: table_data.append([b[i], a[i]]) f = open("tmpfile", "w+") f.write(today) f.close() htmlcode = HTML.table(table_data, header_row=['date', 'description']) if len(table_data) > 0: newfile = "Opinions_" + main_domain_stat + "_".join( today.split()) + ".html" f = open(newfile, "w+") tmp = main.begin + htmlcode + main.end f.write(tmp) f.close() for email in email_list: main.send_email(main.username, main.passwd, email, email, "test subject", tmp) else: print "Nothing new"
def test_notify_response_connection_error(mock_request): responses.add(responses.POST, url, body=RequestConnectionError()) response = send_email(mock_request) assert response == ("connection error", 504)
"transaction_date": "2016-01-31", "status": "pending", "description": "This is a pooled payment for CB2" } }) i = 0 while i < 10000: print '.', i += 1 print '' print "Sending email to People with good financial situation ..." main.send_rich_email("*****@*****.**") print "Sending email to People with bad financial situation ..." main.send_medium_email("*****@*****.**") print "Sending email to People with bad financial situation ..." main.send_poor_email("*****@*****.**") print 'Done!' time.sleep(30) main.send_email("*****@*****.**", "MicroFinance : Thank You", "Thank you for helping out a Cambridge, CB2! We have creditted your CapitalOne Bank Account. Your microlending of $5 will help one of your neighbours to get out of debt really really soon!") print 'Done!' time.sleep(30) main.send_email("*****@*****.**", "MicroFinance : Thank You", "Thank you for reply! We have debitted your CapitalOne Bank Account. We hope this, along with some education, will help you get our of debt really soon!")