I'd like to change the address while saving the email template formatting.

Asked 2 years ago, Updated 2 years ago, 17 views

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.

Code

 outlook = win32 com.client.Dispatches ("Outlook.Application")
mail=outlook.createItemFromTemplate(temp_path)

mail.body=mail.body.format(name)
# mail.HTMLbody=mail.HTMLbody.format(name)

templates

Dear {}, The deadline is xxx days.
Thank you for your cooperation.

Failure Example 1

Dear 〇 様, The deadline is xx days.
Thank you for your cooperation.

Failure Example 2

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.

python

2022-09-30 11:46

1 Answers

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)


2022-09-30 11:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.