I'm trying to create a program that will send and email while also logging to a text file the email's subject line and date/time it was sent. Here is what I have so far.
def send_email():
from exchangelib import Credentials, Account, Message, Mailbox, UTC_NOW
import time
credentials = Credentials('my@email', 'password')
account = Account('my@email', credentials=credentials, autodiscover=True)
m = Message(
account=account,
subject='Test Subject',
body='Test Body',
to_recipients=[
Mailbox(email_address='my@email')
])
text_file = open("Output.txt", "w")
text_file.write(time.strftime("%H:%M:%S"))
text_file.close()
m.send()
send_email()
As it is written currently, the program will send an email (to myself for testing), and will log in a txt file (Output.txt) the current time. What I'm trying to output is this:
Subject:"Test Subject" Date: 4/12/2019 Time: 13:45:09
*Replace date and time with the date and time it was sent.
Granted I still have a little ways to go, I'm starting to get confused on the format of how to do so as I'm new to Python. Is it possible to do all of this and have it print on a single line? Or will it have to print on multiple lines? How should I go about doing this?