Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python create a new mail. Return Line (\n) in body not working

I’m working on a python script which should create a new mail with a specific text body.

Fact is that \n does not work as excepted.

My code is below :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = recipient
    mail.Subject = subject
    mail.HtmlBody = "This is a return line test \nTest"

The body displayed is :

This is a return line test Test

And not :

This is a return line test 
Test

What Am I missing ?

>Solution :

Since you are using HtmlBody , instead of \n, you want to use the HTML style tags for your new-lines. These are called line-breaks, and they look like this: <br>. So you want to replace \n with <br>:

outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.HtmlBody = "This is a return line test <br>Test"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading