python outlook中有多个邮箱,指定特定邮箱发送多个附件 邮件代码
时间: 2023-10-25 11:12:44 浏览: 227
可以使用Python的`win32com`库来操作Outlook。以下是一个示例代码,可以指定特定邮箱发送多个附件邮件:
```python
import win32com.client as win32
outlook = win32.Dispatch('Outlook.Application')
mail = outlook.CreateItem(0)
mail.To = 'recipient@example.com'
mail.Subject = 'Multiple attachments'
mail.Body = 'Please find the attachments below.'
# Set the sender account
senders = outlook.Session.Accounts
for sender in senders:
if sender.DisplayName == "sender_name":
mail._oleobj_.Invoke(*(64209, 0, 8, 0, sender)) # 64209 is the index of the property that represents the sender account
# Attach multiple files
attachments = ["C:/file1.txt", "C:/file2.txt"]
for attachment in attachments:
mail.Attachments.Add(attachment)
mail.Send()
```
在这个示例代码中,`sender_name`需要替换为指定的发件人邮箱的名称,`recipient@example.com`需要替换为收件人的邮箱地址,`C:/file1.txt`和`C:/file2.txt`是要附加的文件路径。
阅读全文