Add Date to the subject

858 views Asked by At
def send_email(status,message):
    yag.send(to=TO_EMAIL,subject="Test Subject: {}".format(status),contents=message)
    logging.info("Mail Sent!")    

How do I add the current date DDMM format just before the subject line like: 0308 Test Subject ? Yagmail Package.

Thanks in advance.

2

There are 2 answers

1
Kenan On BEST ANSWER

You can do it like this

from datetime import datetime
def send_email(status,message):
    date = str(datetime.now().date())[-5:].replace('-', '')
    yag.send(to=TO_EMAIL,subject="{} Test Subject: {}".format(date, status),contents=message)
    logging.info("Mail Sent!")    
1
PixelEinstein On

You should use strftime from the datetime module like this:

from datetime import datetime

def send_email(status,message):
    yag.send(to=TO_EMAIL,subject="{} Test Subject: {}".format(datetime.strftime(datetime.now(), "%d%m"), status),contents=message)
    logging.info("Mail Sent!")