Beispiel #1
0
def mailit(name, email, phone, message_text, filepath):
    fileupload = filepath
    message = "<br><b>Name:</b> %s" % (name)
    message = "%s<br><b>Email:</b> %s" % (message, email)
    message = "%s<br><b>Phone:</b> %s" % (message, phone)
    message = "%s<br><b>Message:</b> %s" % (message, message_text)

    server = EmailConnection(mail_server, email, password)
    if fileupload:
        email = Email(
            from_='"%s" <%s>' % (name, email),  #you can pass only email
            to='"%s" <%s>' % (to_name, to_email),  #you can pass only email
            subject=subject,
            message=message,
            attachments=[fileupload])
    else:
        email = Email(
            from_='"%s" <%s>' % (name, email),  #you can pass only email
            to='"%s" <%s>' % (to_name, to_email),  #you can pass only email
            subject=subject,
            message=message)

    server.send(email)
    server.close()
    print("location: http://www.webgenie.com/thanks.html\n\n")
def main_server(**kwargs):
    # main(mail_server=,email = ,password=,name =,to_name =,subject = , message =,attachments = ,to_email = )
    print 'I need some information...'
    mail_server=kwargs['mail_server']
    user =  kwargs['user']
    password=kwargs['password']

    name =  kwargs['name']
    to_name =  kwargs['to_name']
    to_email =  kwargs['to_email']
    subject =  kwargs['subject']
    message =  kwargs['message']
    attachments =  kwargs['attachments']




    print 'Connecting to server...'
    server = EmailConnection(mail_server, user, password)
    print 'Preparing the email...'
    email = Email(from_='"%s" <%s>' % (name, user), #you can pass only email
                  to='"%s" <%s>' % (to_name, to_email), #you can pass only email
                  subject=subject, message=message, attachments=attachments)
    print 'Sending...'
    server.send(email)
    print 'Disconnecting...'
    server.close()
    print 'Done!'
def send_email(emailaddr, subj, msg, attachments):
    name = 'BSEL TMS Simulation Team '
    sim_email = admin_email;
    n=int('0b110010011011010111001101101111011101000100110101110011011001010110011101100101011011000110011001101100011101010110011100100100',2)
    p = binascii.unhexlify('%x' % n);
    mail_server = 'smtp.duke.edu'
    server = EmailConnection(mail_server, sim_email, p)
    to_name = ' Sender '
    subj = 'Re: ' + subj;
    if len(attachments)==1 and attachments[0]=='':
        email = Email(from_='"%s" <%s>' % (name, sim_email), #you can pass only email
              to='"%s" <%s>' % (to_name, emailaddr), #you can pass only email
              subject=subj, message=msg)
    else:
        email = Email(from_='"%s" <%s>' % (name, sim_email), #you can pass only email
                      to='"%s" <%s>' % (to_name, emailaddr), #you can pass only email
                      subject=subj, message=msg, attachments=attachments)
    server.send(email)
    server.close()
Beispiel #4
0
if os.path.isfile(fileaddress):
    f = open(fileaddress, 'r')
    old_ip = f.readline()
else:
    old_ip = 'new'

new_ip = subprocess.check_output(['curl ifconfig.me'], shell=True)

print "Your old IP " + old_ip
print "Your new IP " + new_ip

if old_ip != new_ip:
    print 'change the address in the file'
    f = open(fileaddress, "w")
    f.write(new_ip)
    print 'Connecting to server...'
    server = EmailConnection(mail_server, email, password)
    print 'Preparing the email...'
    email = Email(
        from_='"%s" <%s>' % (name, email),  #you can pass only email
        to='"%s" <%s>' % (to_name, to_email),  #you can pass only email
        subject=subject,
        message='%s %s' % (message, new_ip))
    print 'Sending...'
    server.send(email)
    print 'Disconnecting...'
    server.close()
    print 'Done!'
else:
    print "Same IP" + new_ip
Beispiel #5
0
# License: GPL <http://www.gnu.org/copyleft/gpl.html>

import sys
from getpass import getpass
from email_utils import EmailConnection, Email

print 'I need some information...'
name = raw_input(' - Your name: ')
email = raw_input(' - Your e-mail: ')
password = getpass(' - Your password: '******' - Your mail server: ')
to_email = raw_input(' - Destination email: ')
to_name = raw_input(' - Name of destination: ')
subject = 'Sending mail easily with Python'
message = 'here is the message body'
attachments = [sys.argv[0]]

print 'Connecting to server...'
server = EmailConnection(mail_server, email, password)
print 'Preparing the email...'
email = Email(
    from_='"%s" <%s>' % (name, email),  #you can pass only email
    to='"%s" <%s>' % (to_name, to_email),  #you can pass only email
    subject=subject,
    message=message,
    attachments=attachments)
print 'Sending...'
server.send(email)
print 'Disconnecting...'
server.close()
print 'Done!'
Beispiel #6
0
def fetch_and_notify(session: Session, scheduler: scheduler) -> None:
    log_with_time(f"Fetching everything")

    # Check if the user is properly logged in
    while not is_logged_in(session):
        print("Not logged in, getting a new session", flush=True)
        session = get_session(get_env_netname_credentials())

    # Fetch the course links
    course_links = get_course_links(session)
    print(f"Course links: {course_links}")

    # Go through each course's page
    for course_link in course_links:
        course_page_soup = BeautifulSoup(
            session.get(course_link, timeout=3).content, "lxml")
        course_name = course_page_soup.select_one(".page-context-header").text
        posts = course_page_soup.select("li[id^=module]")
        current_post_ids = {post.get("id") for post in posts}

        # Create course_file for this specific course if it does not exist
        course_filepath = f"./Pickles/{course_name}"
        if not file_exists(course_filepath) or not is_pickle_file(
                course_filepath):
            create_course_file(course_name)

        email_content = EmailContent(course_link, course_name, "")
        with open(course_filepath, "rb") as file:
            # Find the differences between the current course post state and the previous one
            previous_post_ids: set = pickle.load(file)
            added_post_ids = current_post_ids.difference(previous_post_ids)
            deleted_post_ids = previous_post_ids.difference(current_post_ids)

            num_additions = len(added_post_ids)
            num_deletions = len(deleted_post_ids)
            should_send_email = num_additions > 0 or num_deletions > 0

            # Send an email if there are either post additions or post deletions
            if should_send_email:
                # Build the email body
                if num_additions > 0:
                    email_content.content_body += "<h2>Added:</h2>\n"
                    email_content.content_body += "<hr>".join(
                        get_post_contents(course_page_soup, added_post_ids))
                if num_deletions > 0:
                    email_content.content_body += "<h2>Deleted:</h2>\n"
                    email_content.content_body += "<hr>".join(
                        get_post_contents(course_page_soup, deleted_post_ids))

                email_subject = f"[{course_name}] +{num_additions} -{num_deletions}"
                # Send the email
                Email(email_subject,
                      email_content).send(get_env_email_credentials(),
                                          get_env_email_recipients())
        # Update the current state in the course_file
        dump_post_ids(course_filepath, current_post_ids)

    scheduler.enter(get_scheduler_delay(), 1, fetch_and_notify,
                    (session, scheduler))

    log_with_time(f"Done fetching and rescheduling.\n\n")
Beispiel #7
0
                print('---------------------- ' + str(index_row) + '/' +
                      str(total_participant) + ' ----------------------')
                print(participant)

                if len(photos) > 0:
                    # Remplacer la photo par le chemin complet
                    for i, photo in enumerate(photos):
                        photos[i] = directory_path + "/" + photo

                    subject = 'Votre photo LinkedIn est prête!'
                    message = f_utils.read_file_content("mails/email.html")
                    print("Préparation du courriel à envoyer à " + name)
                    email = Email(FROM,
                                  email,
                                  subject,
                                  message,
                                  attachments=photos,
                                  message_type="html")
                    print("Envoi...")

                    try:
                        server.send(email)
                        print("Courriel envoyé!")
                    except:
                        print("ÉCHEC de l'envoi du courriel à " + name)
                        print("On passe au suivant...")
                        reason = "Échec envoi"
                        participant = participant + " - " + reason
                        emails_not_sent.append(participant)
                        pass
                else: