Search code examples
pythonyagmail

Add custom text message after break line


The below code snippet sends email with status. If I want to add another line break with text as Sent from Scheduler. What could be the possible way ?

def send_email(status,message):
    date = str(datetime.now().date())[-5:].replace('-', '/')
    yag.send(to=TO_EMAIL,subject="{} Rebuild Code: {}".format(date, status),contents=message)
    logging.info("Mail Sent!")

Thanks!


Solution

  • Please try this updated code.

    Update:

    def send_email(status,message):
        date = str(datetime.now().date())[-5:].replace('-', '/')
        message = "{}\n{}".format(message, 'Sent from Scheduler'
        yag.send(to=TO_EMAIL,subject="{} Rebuild Code: {}".format(date, status),contents=message))
        logging.info("Mail Sent!")
    

    Here, instead of just returning the message, it can be updated as "{}\n{}".format(message, 'Sent from Scheduler') \n is the single line break. If you want multiple line breaks you can use \n\n.