python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

Mail body formatting

Open mohit12r opened this issue 4 years ago • 1 comments

I want read the mail body exactly in the same format as it is received, but when I'm reading mail body from HTML mail body format gets distorted, Is there any way to read mail body in plain text format and in the exact same format it was received. Also while sending mails I'm sending a formatted string which consists of '\n' for formatting but entire body appears in single line, entire formatting gets distorted. please any one can help to resolve this issue. Below is the code to read mail body and send a formatted string:

read mail body:

mail_body=msg.body soup = bs.BeautifulSoup(mail_body,'lxml') soups=soup.find_all('body')

    for i in soups:
        # print(i)
        mail_body_content=i.text

Send mail body:

m.body = "%PREFIX="+prefix+"\n"+"%ENDUSER="+sender_name+"\n"+"%Requester="+"[email protected]"+"\n"++"%DESCRIPTION="+"login issue"

m.send()

mohit12r avatar Apr 06 '21 07:04 mohit12r

You can access the body just with msg.body. That's what the api returns. But you have a helper method called get_body_text if the body type is text it just returns the text. If the body type is html it parses the html and returns the parsed text.

You will find more if you dig a little bit into the code

alejcas avatar Apr 06 '21 10:04 alejcas