

Next, press Alt+F11 keys together to open the VBA editor. Open an Excel file, a macro enabled file.

Therefore, please make sure you have the latest Outlook installed and configured. Note: You must have Ms-Office Outlook installed in your computer. Its Christmas today, and when you open your Excel workbook, it should check the date, and if its 25th of December, extract emails from your worksheet and send emails to multiple recipients (bulk email). Let us assume, you have a list of emails in your Excel worksheet. I’ll show you how you can send emails to multiple recipients automatically (based on time and date of the year) from your Excel worksheet using a simple macro and Outlook. Many of us would be preparing to send emails to our colleagues, clients, friends and family. If you liked this article, please hit the small heart below.Well, its holiday season again and Christmas is approaching, followed by the New Year. I originally published this article here.
AUTOMATIC EMAIL SENDER CODE CODE
There you go! I believe the code is now fairly clear.įeel free to copy and tweak it as necessary.Īpart from the official Python docs, I would also like to mention this resource which helped me a lot. # Terminate the SMTP session and close the connection

# send the message via the server set up earlier. # Prints out the message body for our sake Message = message_template.substitute(PERSON_NAME=name.title()) # add in the actual person name to the message template S = smtplib.SMTP(host='your_host_address_here', port=your_port_here) Message_template = read_template('message.txt') Names, emails = get_contacts('mycontacts.txt') # read contacts Template_file_content = template_file.read() With open(filename, 'r', encoding='utf-8') as template_file: Returns a Template object comprising the contents of the With open(filename, mode='r', encoding='utf-8') as contacts_file: Return two lists names, emails containing names and email addresses Once that is done, you can send the message using the handy send_message() function of the SMTP object you created earlier.įrom import MIMEMultipart In this particular example I’m deleting the MIMEMultipart object and re-creating it each time you iterate through the loop. Notice the word “ $ with the actual name extracted from the contacts file using the templating mechanism in Python. Next, we have the message template file message.txt. I’ll leave it to the programming logic to convert any fields to upper-case or sentence-case if necessary. We have the name followed by the email address. Let’s say you have a contacts file mycontacts.txt as follows: ~ $ cat mycontacts.txt Now let me walk you through the whole process.
AUTOMATIC EMAIL SENDER CODE HOW TO
By Arjun Krishna Babu How to send emails using PythonĪs a learning exercise, I recently dug into Python 3 to see how I could fire off a bunch of emails.
