How to paste an attachment into an email line with Python

Asked 2 years ago, Updated 2 years ago, 18 views

I looked it up online, but it's hard to find a solution, so I'll ask you a question.

Currently, I am creating a tool to automatically send mail to Python and win32com, but I am thinking of attaching a file to the sentence for execution in rich text format.

Assumed

Attach the file below.
{Attachment} 
Thank you.

Usage Code

outlook==win32com.client.Dispatches("Outlook.Application")
mail=outlook.createItemFromTemplate(template_item)

mail.to=""
mail.cc=""
US>"mail.bcc="
mail.bodyformat=3#3:rich text
mail.Attachment.Add(attachment)
mail.Display (True)

However, in the case of the above code, all files are attached to the bottom of the email.I thought about writing {} to a predetermined location and inserting it with format(), but only the file name was written.
How do I attach a file to the line?

python

2022-09-30 19:12

1 Answers

By running Display before Attachment.Add, you were able to attach files to any line.

mail.to=""
mail.cc=""
US>"mail.bcc="
mail.bodyformat=3
mail.Display(True)#Change Timing
mail.Attachment.Add (Source=attachment, Position=position)


2022-09-30 19:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.