예제 #1
0
    def check_in_gmail(self, email_list, petitions_list):
        """
        When petition registration success, the user's details transfer to salesforce. if salesforce receive
        email with this form: [email protected], salesforce will send the user details to
        [email protected].
        This function search in [email protected] inbox for email from saleforce
        with the user's details, if the email not found the test failed and email about the failure will be send.
        Also write registration detail in google sheet named 'Report'([email protected] is the owner of this sheet)
        accept:
        email_list - list of email that the bot used to sign ups.
        petitions_list - list of petitions url the bot signed up.
        """
        service = auth.get_service_gmail()  # open gmail API client
        client = auth.get_service_sheet()  # open google sheet API client
        report_sheet = client.open(
            "Report"
        ).sheet1  # open report sheet, will insert success or failure

        petitions_index = 0
        for email_address in email_list:
            num_emails_received = emailfunc.petition_emails(
                service, 'me', email_address)
            if num_emails_received == 1:
                status = "Succeed! Salesforce email received"
            else:
                status = "Failed - Found " + str(
                    num_emails_received) + " emails instead of 1"
            row_status = [
                str(datetime.today())[0:16], "Petition",
                petitions_list[petitions_index], email_address, status
            ]
            report_sheet.insert_row(row_status, 2)
            if num_emails_received != 1:
                emailfunc.signup_failed_email(service, row_status)
            petitions_index += 1
예제 #2
0
    def check_in_sheets(self, sheet):
        """
        Some of the signed ups transfer to google sheet, this function check if the registration arrived to
        the google sheet. If it does, the registration delete from the google sheet.
        If the registration doesn't arrive to the google sheet, failure email will be sent to dev.
        Also there is a method that check if there only one row deleted from the google sheet, in case more or
        less then one row deleted the test failed and email sent to dev.
        Also write registration detail in google sheet named 'Report'([email protected] is the owner of this sheet)
        """
        client = auth.get_service_sheet()  # open google sheet API client
        service = auth.get_service_gmail()  # open gmail Api
        report_sheet = client.open("Report").sheet1  # open report sheet, will insert success or failure
        self.sheet = sheet

        row_failed_msg = "Registration's email not found in google sheet!!!"
        row_success_all_msg = "Sign up succeed and removed from google sheet"
        row_remove_more_msg = "Sign up succeed but the bot removed more than one row in the google sheet!!!"
        row_not_remove_msg = "Sign up succeed but the bot failed to remove the test email from the google sheet"
        sign_up_sheet = client.open(self.sheet).sheet1  # open sign up form sheet
        time_now = str(datetime.today())[0:16]
        row_failed = [time_now, self.sheet, self.site, self.email, row_failed_msg]
        row_succeed_all = [time_now, self.sheet, self.site, self.email, row_success_all_msg]
        row_remove_more = [time_now, self.sheet, self.site, self.email, row_remove_more_msg]
        row_not_remove = [time_now, self.sheet, self.site, self.email, row_not_remove_msg]
        
        try:
            sign_up_sheet.find(self.email)  # search if the test email found in sign up form sheet
            rows_before_delete = len(sign_up_sheet.col_values(1))
            sign_up_sheet.delete_row(sign_up_sheet.find(self.email).row)
            rows_after_delete = len(sign_up_sheet.col_values(1))
            gap = str(rows_before_delete - rows_after_delete)
            row_failed.append(gap)  # adding the number of rows that remove
            row_succeed_all.append(gap)
            row_remove_more.append(gap)
            row_not_remove.append(gap)
            try:
                sign_up_sheet.find(self.email)  # try to find the test email again
                if rows_before_delete - rows_after_delete > 1:  # check if more then one row was delete
                    report_sheet.insert_row(row_remove_more, 2)  # report that more then one row was delete
                    report_sheet.insert_row(row_not_remove, 2)  # tell us the test email found after deleting
                    emailfunc.signup_failed_email(service,
                                                  row_remove_more)  # send email, open the func in order to see to who
                    emailfunc.signup_failed_email(service, row_not_remove)
                else:
                    report_sheet.insert_row(row_not_remove, 2)  # tell us the test email found after deleting
                    emailfunc.signup_failed_email(service, row_not_remove)
            except gspread.CellNotFound:
                if rows_before_delete - rows_after_delete > 1:  # check if more then one row was delete
                    report_sheet.insert_row(row_remove_more, 2)  # report that more then one row was delete
                    emailfunc.signup_failed_email(service, row_remove_more)
                else:
                    report_sheet.insert_row(row_succeed_all, 2)  # tell us that everything work right
        except gspread.CellNotFound:
            report_sheet.insert_row(row_failed, 2)  # tell us that test email didn't found in the sheet
            emailfunc.signup_failed_email(service, row_failed)
예제 #3
0
import requests
from requests.exceptions import ConnectionError
import random
import time
import json
import base64
from email.mime.text import MIMEText
from apiclient import errors
import auth

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

gmail_service = auth.get_service_gmail()


def create_message(sender, to, subject, message_text):
    """Create a message for an email.

  Args:
    sender: Email address of the sender.
    to: Email address of the receiver.
    subject: The subject of the email message.
    message_text: The text of the email message.

  Returns:
    An object containing a base64url encoded email object.
  """
    message = MIMEText(message_text)
    message['to'] = to
    message['from'] = sender