I am creating an automatic mail sending program with win32com, but I used the format method to change the address to be written at the beginning of the email.
outlook = win32 com.client.Dispatches ("Outlook.Application")
mail=outlook.createItemFromTemplate(temp_path)
mail.body=mail.body.format(name)
# mail.HTMLbody=mail.HTMLbody.format(name)
Dear {},
The deadline is xxx days.
Thank you for your cooperation.
Dear 〇 様,
The deadline is xx days.
Thank you for your cooperation.
Dear 〇 様,
The deadline is xxx days.
Thank you for your cooperation.
However, immediately after the format method, the format (character color, font, thickness, etc.) and tabs that were set in the template were initialized.In the case of HTMLBody, all but the formatting was initialized and unnecessary line breaks were left blank for each sentence.
Is there any other way to change a specific string such as the address other than the format?
I would appreciate it if you could let me know.
The template file (msg format) was loaded with createItemFromTemplate, but it was canceled and resolved by writing the HTML code for the template on the source code.
Editing emails in HTML format was more convenient because you can also set fonts and other settings.
name="imbzer"
outlook = win32 com.client.Dispatch("Outlook.Application")
mail=outlook.createItem(0)
mail_temp='"
<html>
<body>
{} Dear <br>
The deadline is <b>xxx day</b>.<br>
Thank you.
<body>
<html>
'''
mail.HTMLbody=mail_temp.format(name)
© 2024 OneMinuteCode. All rights reserved.