问题
I need to create an email draft and save in msg format without launching the outlook application.
(Or)
I have an existing draft msg file, I need to modify the sender, body, and attachment to that file and save as msg file.
I tried win32 it is working fine, but it is launching the outlook application in my system. In my server, there is no outlook application.
Can you please tell me is there any other ways to generate the msg file.
回答1:
If you don't want to to use the Outlook Object Model, you are pretty much limited to either using a library like Aspose (it handles MSG files without having to install Outlook, but your mileage may vary) or Redemption (disclosure: I am its author) - it requires the MAPI system to be installed (which means Outlook must be installed), but it won't start Outlook if you are using RDOSession.CreateMsgFile
(ollowed by setting various RDOMail properties and/or importing an existing MSG file using RDOMail.Import
followed by RDOMail.Save
.
Update per OP request. I don't use Python, but in VB script it would be something like the following:
Set Session = CreateObject("Redemption.RDOSession")
set newMsg = Session.CreateMessageFromMsgFile("c:\temp\new.msg")
newMsg.Import("c:\temp\template.msg", 3)
newMsg.Body = "updated body"
newMsg.Save
回答2:
You can create an email draft and save it as MSG with Aspose.Email for Python via .NET using the code sample given below:
eml = MailMessage()
# Set from, to, subject and body properties
eml.from_address = "sender@domain.com";
eml.to.append("receiver@domain.com");
eml.subject = "This is test message";
eml.body = "This is test body";
# Create an instance of the MapiMessage class and pass MailMessage as argument
outlookMsg = MapiMessage.from_mail_message(eml);
# Save the message (MSG) file
strMsgFile = "CreatingAndSavingOutlookMessages_out.msg"
outlookMsg.save(dataDir + strMsgFile);
Note: I am working as Support developer/ Evangelist at Aspose.
来源:https://stackoverflow.com/questions/53481004/create-outlook-draft-email-in-python-with-out-launching-outlook-application