简体   繁体   English

用于更改 Outlook 邮件项目主题行的 Python 函数

[英]Python function for changing the subject line of an Outlook mail item

Is there a Python function for changing the subject line of an Outlook mail item?是否有用于更改 Outlook 邮件项目主题行的 Python 函数?

I have seen solutions for this using VBA.我已经看到使用 VBA 解决这个问题。 Was looking for a function/ method in python.正在寻找 python 中的函数/方法。

Thanks谢谢

Update : Here's what i am trying :更新:这是我正在尝试的:

import win32com.client as win32
outlook = win32.gencache.EnsureDispatch('Outlook.Application')
mapi = outlook.GetNamespace('MAPI')
folder = mapi.GetDefaultFolder(6)
messages = folder.Items

# Change the current subject line to 'Testing subject change'
messages.GetFirst().Subject = 'Testing subject change'

However, the subject line doesn't change.但是,主题行不会改变。 Is there any specific function i should be using?我应该使用任何特定功能吗?

This short piece of code will replace all Subject lines of all emails in the specified folder, in this case "Drafts" (provided your Office is in English)这段简短的代码将替换指定文件夹中所有电子邮件的所有主题行,在本例中为“草稿”(前提是您的办公室是英文的)

import win32com.client as win32

outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI")
acc = outlook.Folders("myaddress@provider.com")
eMailFolder = acc.folders("Drafts") #This is the localized name of your folder, as it appears in Outlook's GUI

def replaceSubjectLine(email:object):
        print(email.Subject)
        email.Subject = "This is the new subject line"
        email.Save
        print(email.Subject)

for message in eMailFolder.Items:
    replaceSubjectLine(message)

In Short: You read in the MailItem Object into Python, then changed one of its Properties (Subject), but you never .Save the changed MailItem to Outlook.在短:你在的MailItem对象成Python读,然后改变了其属性(主题)中的一个,但你永远不.Save的改变的MailItem到Outlook。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python邮件在Outlook主题行中放置了无法计算的空间 - Python mail puts unaccounted space in Outlook Subject line 使用Python在Outlook中移动邮件项目 - Move Mail item in Outlook with Python 如何使用python搜索主题行中有字符串的Outlook电子邮件? - How to search outlook email having string in subject line using python? Outlook根据日期、发件人和主题行使用MAPI python下载附件 - Outlook download attachments with MAPI python based on date, sender and subject line 在 python 中,当我对 Outlook 邮件项目使用“回复”功能时,之前的对话未附加 - In python when I use 'Reply' function for outlook mail item the previous conversation is not appending 如何在python中解码编码电子邮件主题行? - How to decode encode e-mail subject line in python? 主题行未出现在从python发送的smtp邮件中 - Subject line not coming in the smtp mail sent from python 从python中的函数调用时,邮件传递时没有主题 - mail is delivering without subject when calling from function in python 在Python邮件功能中填充其他电子邮件字段,例如“主题” - Populate other email fields like Subject in Python mail function python:希望从今天收到的 outlook 邮件中保存附件并带有特定主题 - python: looking to save attachments from outlook mail received Today and with specific subject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM