Hi everyone. To introduce myself... I'm new here and signed up today.
I have been learning Python for 2 weeks now, and it hasn't been an easy learning curve.
I'm learning Python to help automate office and admin tasks. Not to become a programmer, but am eager to actually GET it rather than just intellectually understand it.
Right now, I have managed to successfully piece together code which helps me attach more than one image using Python. I learned the difference between sending 1 and more than one image...
My problem is this:
I would like to send multiple attachments (using Microsoft Word & Excel files) using Python.
My limited understanding is that files and images in Python each have different requirements in terms of code.
I humbly admit I had to refer to tutorials and Python documentation, in order to help me piece together certain missing information (I find it hard to remember and apply code if it is not immediately useful or the examples are not related to my own project).
I would like to ask you, can you please look through my code and help me via provided examples, what code would be most useful, where and what imports I need to do that may be different to attaching images?
I know there is documentation online about this, it's simply that I have found this provided code works for me and I understand it and want to stick to it as a beginner, and the vast majority of times I try to replicate code and piece it from multiple sources, it most often doesn't work and I end up in circles. (I don't know if that's most people or just me).
I would appreciate examples and how I can learn to do this for myself.
Enough chatter, here is the code I made below (Any requested info, I will provide. Thank you!):
I have been learning Python for 2 weeks now, and it hasn't been an easy learning curve.
I'm learning Python to help automate office and admin tasks. Not to become a programmer, but am eager to actually GET it rather than just intellectually understand it.
Right now, I have managed to successfully piece together code which helps me attach more than one image using Python. I learned the difference between sending 1 and more than one image...
My problem is this:
I would like to send multiple attachments (using Microsoft Word & Excel files) using Python.
My limited understanding is that files and images in Python each have different requirements in terms of code.
I humbly admit I had to refer to tutorials and Python documentation, in order to help me piece together certain missing information (I find it hard to remember and apply code if it is not immediately useful or the examples are not related to my own project).
I would like to ask you, can you please look through my code and help me via provided examples, what code would be most useful, where and what imports I need to do that may be different to attaching images?
I know there is documentation online about this, it's simply that I have found this provided code works for me and I understand it and want to stick to it as a beginner, and the vast majority of times I try to replicate code and piece it from multiple sources, it most often doesn't work and I end up in circles. (I don't know if that's most people or just me).
I would appreciate examples and how I can learn to do this for myself.
Enough chatter, here is the code I made below (Any requested info, I will provide. Thank you!):
import os import smtplib from email.message import EmailMessage #This helps us upload more than one image via Python import imghdr #Notice we are using Windows "Enviornment Variables", in order to hide our sensitive data Email_User = os.environ.get("Andree_Email") Email_Password = os.environ.get("Andree_Pass") msg = EmailMessage() msg['Subject'] = "Send candy" msg['From'] = Email_User msg['To'] = Email_User msg.set_content("Can you send me some candy from Florida?") files = ["c:\\Users\\Matti\\Desktop\\Bot External API.png","c:\\Users\\Matti\\Desktop\\Parameters.png"] for file in files: with open(file, "rb") as f: file_data = f.read() file_type = imghdr.what(f.name) file_name = f.name msg.add_attachment(file_data, maintype = "image", subtype = file_type, filename = file_name) #587 is standard internet server connection, but 465 is with SSL encrypted connection with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp: smtp.login(Email_User, Email_Password) smtp.send_message(msg)