Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file attachment confirmation being asked for every receipient #2

Closed
aahnik opened this issue Jun 25, 2020 · 1 comment
Closed

file attachment confirmation being asked for every receipient #2

aahnik opened this issue Jun 25, 2020 · 1 comment

Comments

@aahnik
Copy link
Owner

aahnik commented Jun 25, 2020

No description provided.

@aahnik
Copy link
Owner Author

aahnik commented Jun 26, 2020

issue fixed

inside extract.py

def confirm_attachments():
    attachments = []
    filenames = []
    for filename in os.listdir('ATTACH'):

        entry = input(f"""TYPE IN 'Y' AND PRESS ENTER IF YOU CONFIRM T0 ATTACH {filename} 
                                TO SKIP PRESS ENTER: """)
        confirmed = True if entry == 'Y' else False
        if confirmed:
            filenames.append(filename)
            attachment = open(f'{os.getcwd()}/ATTACH/{filename}', "rb")
            attachments.append(attachment)

    return filenames, attachments

inside send.py

filenames, attachments = extract.confirm_attachments()
with smtplib.SMTP_SSL(smtp_server, port, context=con) as server:
    server.login(sender_address, auth_code)
    for receiver_address, receiver_name in extract.data():
           # ... 
         for attachment, filename in zip(attachments, filenames):
             attach_part = MIMEBase('application', 'octet-stream')
             attach_part.set_payload((attachment).read())
             encoders.encode_base64(attach_part)
             attach_part.add_header('Content-Disposition',
                                   f"attachment; filename= {filename}")
             multipart_msg.attach(attach_part)

@aahnik aahnik closed this as completed Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant