[英]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.