Example #1
0
def send_success_message():
    """Sends an email

    Creates a Gmail API service object and then creates an email and sends that email
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    sender = "*****@*****.**"
    to = "*****@*****.**"
    subject = "Success!"
    message_text = ""

    message = mail.CreateMessage(sender, to, subject, message_text)
    mail.SendMessage(service, "me", message)
Example #2
0
def send_error_message(
):  #An error message corresponds to something that causes the entire program to fail and exit
    """Sends an email

    Creates a Gmail API service object and then creates an email and sends that email
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    sender = "*****@*****.**"
    to = "*****@*****.**"
    subject = "Failure!"
    message_text = "Received Error Message:\n\n" + message_body

    message = mail.CreateMessage(sender, to, subject, message_text)
    mail.SendMessage(service, "me", message)
Example #3
0
def main():
    """Shows basic usage of the Gmail API.
    Lists the user's Gmail labels.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('gmail', 'v1', credentials=creds)

    msg = send_email.CreateMessage(
        'me', '*****@*****.**', "Introduction", '''Hi <NAME>,

I'm a recent post-grad in Data Informatics(CS) from USC, passionate about building statistical models and smart data-driven applications with my skills in Machine learning, Deep learning, Computer Vision and Natural Language Processing. I have previous experience of 2 years as a software engineer in security platforms team at Fidelity Investments, and as a data scientist intern for 8 months at Dermalogica (Unilever), building and deploying machine learning models. These have helped me gain a broader understanding of data related problems in both, service and product-based companies. I am looking for full time data science and machine learning roles. 
I have completed my degree program and available to start full time immediately.
I would love to have a quick chat about opportunities at <Company.>



Regards,
Tanay Shankar
MS in Data Informatics
University of Southern California
''')
    send_email.SendMessage(service, 'me', msg)
Example #4
0
def main():
    """Shows basic usage of the Gmail API.
    Lists the user's Gmail labels.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:

            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('gmail', 'v1', credentials=creds)


    # Call the Gmail API
    file = open("/Users/[email protected]/PycharmProjects/Sprint01/myTemplateWeatherAlert.txt", "r")
    email = file.read()
    file.close()

    for teamMember in ['*****@*****.**', '*****@*****.**']:
        message = send_email.CreateMessageWithAttachment("*****@*****.**", teamMember, "The gmail api",
                                                     email,
                                                     "/Users/[email protected]/PycharmProjects/Sprint01",
                                                     "map.jpg")
        send_email.SendMessage(service, "me", message)
Example #5
0
def send_custom():
    """Sends an email with an attachment

    Creates a Gmail API service object and then creates an email and sends that email
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    sender = "*****@*****.**"
    to = "*****@*****.**"
    subject = "Custom Subject"
    message_text = "custom text"
    filedir = ""
    filename = ""

    if filedir == "":
        message = mail.CreateMessage(sender, to, subject, message_text)
    else:
        message = mail.CreateMessageWithAttachment(sender, to, subject,
                                                   message_text, filedir,
                                                   filename)
    mail.SendMessage(service, "me", message)
Example #6
0
def send_alarm_notification():
    """Sends an email to the specified email address, addressed to specified person

    Creates a Gmail API service object and then creates an email and sends that email
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    sender = "*****@*****.**"
    to = recipient_email_address

    if did_fail == "False":
        subject = "Nick woke up to one of your alarms today!"
        addressing_part = "Dear " + first_name + ",\n\n"
        url_part = "Nick woke up to the following video:\n" + url + "\n"
        wake_up_time_part = "It woke him up in " + wake_up_time + "\n"
        if was_favorited == "True":
            favorited_part = "And Nick favorited your video!"
        else:
            favorited_part = ""
        additional_feedback_part = "\nNick's reaction to the video: " + additional_feedback + "\n"
        end_part = "\n\nRegards,\nSnoozinforabruisin"
        message_text = addressing_part + url_part + wake_up_time_part + favorited_part + additional_feedback_part + end_part

    elif did_fail == "True":
        subject = "Oops...one of your alarms didn't wake Nick up"
        addressing_part = "Dear " + first_name + ",\n\n"
        url_part = "One of your videos was selected this morning:\n" + url + "\n\n" + "...but Nick didn't wake up to it...he might still be snoozin!"
        end_part = "\n\nRegards,\nSnoozinforabruisin"
        message_text = addressing_part + url_part + end_part
    else:
        print("Hmmmm")

    message = mail.CreateMessage(sender, to, subject, message_text)
    mail.SendMessage(service, "me", message)