Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Muzammil-khan/f17968d81fdb41fd2490f727ab41d68e to your computer and use it in GitHub Desktop.

Select an option

Save Muzammil-khan/f17968d81fdb41fd2490f727ab41d68e to your computer and use it in GitHub Desktop.
This Gist contains code snippets for examples of Aspose.Email for Python via .NET
Examples related to Aspose.Email for Python via .NET
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
msg = MailMessage("[email protected]", "[email protected]", "subject", "message")
client.subscribe_folder(client.current_folder.name)
client.append_message(client.current_folder.name, msg)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Combine Queries with And
builder = ImapQueryBuilder("utf-8")
builder.from_address.contains("SpecificHost.com")
#Date Range
builder.internal_date.before(dt.datetime.now())
builder.internal_date.since(dt.datetime.today() - timedelta(days=7))
#Combining Queries with OR
builder.either(builder.subject.contains("test"), builder.from_address.contains("[email protected]"));
#Filtering on Internal Date
builder.internal_date.on(dt.datetime.now())
#Case-Sensitive Email Filtering
builder.subject.contains("Newsletter", True)
builder.internal_date.on(dt.datetime.now())
#GetMessagesWithCustomFlag
builder.has_flags(ImapMessageFlags.keyword("custom1"))
builder.has_no_flags(ImapMessageFlags.keyword("custom2"))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
builder = ImapQueryBuilder()
builder.subject.contains("Newsletter", True)
query = builder.get_query()
msgsColl = client.list_messages(query)
print("Total Messages fulfilling search criterion: " + str(len(msgsColl)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
folderName = "MovedMessagesToFolder"
#List messages from Inbox to verify that messages have been copied
msgsCollection = client.list_messages()
print("Total Messages in Inbox before appending: " + str(len(msgsCollection)))
#Append 2 new Messages to Inbox
msg = MailMessage("[email protected]", "[email protected]", "Message1TobeMoved", "message")
msgId1 = client.append_message(msg)
msg2 = MailMessage("[email protected]", "[email protected]", "Message1TobeMoved", "message")
msgId2 = client.append_message(msg2)
#List messages from Inbox to verify that messages have been copied
msgsCollection = client.list_messages()
print("Total Messages in Inbox after appending: " + str(len(msgsCollection)))
msgsIds = []
msgsIds.append(msgId1)
msgsIds.append(msgId2)
#Copy message to another folder
client.copy_messages(msgsIds, folderName)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
print(client.uid_plus_supported)
#Append some test messages
client.select_folder("Inbox")
uidList = []
messageInfoCol = client.list_messages()
print("Total messages in Inbox before appending: " + str(len(messageInfoCol)))
#No. of messages to be appended
messageNumber = 2
message = MailMessage("[email protected]", "[email protected]", "Message 1", "Add ability in ImapClient to delete message")
emailId = client.append_message(message)
uidList.append(emailId)
message = MailMessage("[email protected]", "[email protected]", "Message 2", "Add ability in ImapClient to delete message")
emailId = client.append_message(message)
uidList.append(emailId)
#Now verify that all the messages have been appended to the mailbox
messageInfoCol = client.list_messages()
print("Total messages in Inbox after appending: " + str(len(messageInfoCol)))
client.delete_messages(uidList, True)
client.commit_deletes()
messageInfoCol = client.list_messages()
print("Total messages in Inbox after deletion: " + str(len(messageInfoCol)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
message = MailMessage("[email protected]", "[email protected]", "Message deletion using IMAP Client", "EMAILNET-35227 Add ability in ImapClient to delete message")
messageInfoCol = client.list_messages()
print("Total messages in Inbox before appending: " + str(len(messageInfoCol)))
emailId = client.append_message(message)
print("Email appended to inbox with email Id: " + emailId)
# Now verify that all the messages have been appended to the mailbox
messageInfoCol = client.list_messages()
print("Total messages in Inbox after appending: " + str(len(messageInfoCol)))
client.delete_message(emailId)
client.commit_deletes()
messageInfoCol = client.list_messages()
print("Total messages in Inbox after deletion: " + str(len(messageInfoCol)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as conn:
conn.select_folder("Inbox")
for msg in conn.list_messages():
conn.save_message(msg.unique_id, dataDir + msg.unique_id + "_out.eml")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
builder = ImapQueryBuilder()
builder.subject.contains("Newsletter")
builder.internal_date.on(dt.datetime.now())
query = builder.get_query()
msgsColl = client.list_messages(query)
print("Total Messages fulfilling search criterion: " + str(len(msgsColl)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Filter on Today's Date
builder = ImapQueryBuilder()
builder.internal_date.on(dt.datetime.now())
#Filter messages on Date Range
builder.internal_date.before(dt.datetime.now());
builder.internal_date.since(dt.datetime.today() - timedelta(days=7))
#Specific Sender
builder.from_address.contains("[email protected]")
#Specific Domain
builder.from_address.contains("SpecificHost.com")
#Specific Recipient
builder.to.contains("recipient");
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
folderInfoColl = client.list_folders();
#Iterate through the collection to get folder info one by one
for folderInfo in folderInfoColl:
print("Folder name is " + folderInfo.name)
folderExtInfo = client.get_folder_info(folderInfo.name)
print("New message count: " + str(folderExtInfo.new_message_count));
print("Is it readonly? " + str(folderExtInfo.read_only));
print("Total number of messages " + str(folderExtInfo.total_message_count));
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as conn:
conn.select_folder("Inbox")
msgsColl = conn.list_messages(True);
print("Total Messages: " + str(len(msgsColl)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
pages = []
itemsPerPage = 1
pageInfo = client.list_messages_by_page(itemsPerPage)
print(pageInfo.total_count)
pages.append(pageInfo)
while not pageInfo.last_page:
pageInfo = client.list_messages_by_page(pageInfo.next_page)
pages.append(pageInfo)
retrievedItems = 0
for folderCol in pages:
retrievedItems+= len(folderCol.items)
print(str(retrievedItems))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as conn:
conn.select_folder("Inbox")
for msg in conn.list_messages():
print( "From: '{}', MIME Id: {}".format(msg.from_address, msg.message_id) )
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as conn:
conn.select_folder("Inbox")
for msg in conn.list_messages():
print( "From: '{}', MIME Id: {}".format(msg.from_address, msg.message_id) )
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
folderName = "N1Renamed"
#Append a new Message to Inbox
msg = MailMessage("[email protected]", "[email protected]", "subject", "message")
msgId = client.append_message( msg)
#List messages from Inbox
msgsCollection = client.list_messages()
print("Total Messages in Inbox: " + str(len(msgsCollection)))
#Move message to another folder
client.move_message(msgId, folderName)
#List messages from Inbox
msgsCollection = client.list_messages()
print("Total Messages in Inbox: " + str(len(msgsCollection)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
client.select_folder("Inbox")
msg = MailMessage("[email protected]", "[email protected]", "subject", "message")
client.subscribe_folder(client.current_folder.name)
uid = client.append_message(client.current_folder.name, msg)
messageExtraFields = ["X-GM-MSGID", "X-GM-THRID"]
#retreive the message summary information using it's UID
messageInfoUID = client.list_message(uid, messageExtraFields)
#retreive the message summary information using it's sequence number
messageInfoSeqNum = client.list_message(1, messageExtraFields)
#List messages in general from the server based on the defined properties
messageInfoCol = client.list_messages(messageExtraFields)
print(str(len(messageInfoCol)))
messageInfoFromList = messageInfoCol[0]
if messageInfoFromList.extra_parameters is not None:
for paramName in messageExtraFields:
print(messageInfoFromList.extra_parameters.has_key(paramName))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
capabilities = client.get_capabilities()
for val in capabilities:
print(val);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as conn:
conn.select_folder("Inbox")
for msgInfo in conn.list_messages():
msg = conn.fetch_message(msgInfo.unique_id)
msg.save(dataDir + msgInfo.unique_id + "_out.msg", aspose.email.SaveOptions.default_msg_unicode)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as client:
message = MailMessage("[email protected]", "[email protected]", "subject", "message");
#Append the message to mailbox
uid = client.append_message("Inbox", message);
client.add_message_flags(uid, ImapMessageFlags.keyword("custom1"))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
with ImapClient("imap.gmail.com", 993, "username", "password") as conn:
conn.select_folder("Inbox")
conn.change_message_flags(1, ImapMessageFlags.is_read)
conn.remove_message_flags(1, ImapMessageFlags.is_read)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = ImapClient("imap.domain.com", 993, "[email protected]", "pwd")
client.security_options = SecurityOptions.SSLIMPLICIT
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client()
# Specify host, username, password, Port and SecurityOptions for your client
client.host = "pop.gmail.com";
client.username = "[email protected]";
client.password = "your.password";
client.port = 995;
client.security_options = SecurityOptions.AUTO;
print("Connected to POP3 server.");
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("imap.gmail.com", 993, "username", "password")
client.security_options = SecurityOptions.AUTO
# Delete all the message one by one
messageCount = client.get_message_count()
print("Total messages in inbox: " + str(messageCount))
for i in range(1,messageCount):
client.delete_message(i)
client.commit_deletes()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
builder = MailQueryBuilder()
#Filtering on Subject
builder.subject.contains("Newsletter")
#Filtering on Internal Date
builder.internal_date.on(dt.datetime.now())
#Filtering on Date Range
builder.internal_date.before(dt.datetime.now())
builder.internal_date.since(dt.datetime.today() - timedelta(days=7))
#Filtering on Sender
builder.from_address.contains("[email protected]")
#Filtering on Specific Domain
builder.from_address.contains("SpecificHost.com");
#Filtering on specific Recipient
builder.to.contains("recipient")
#Combining Queries with OR
#builder.either(builder.subject.contains("test"), builder.from_address.contains("[email protected]"))
#Case-Sensitive Email Filtering
builder.subject.contains("Newsletter", True)
msgsColl = client.list_messages(builder.get_query())
print("Filtered Messages Count: " + str(len(msgsColl)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
#Get the size of the mailbox, Get mailbox info, number of messages in the mailbox
i = client.get_message_count();
print("No. of emails: " + str(i));
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Get the size of the mailbox, Get mailbox info, number of messages in the mailbox
nSize = client.get_mailbox_size();
print("Mailbox size is " + str(nSize) + " bytes.");
info = client.get_mailbox_info();
nMessageCount = info.message_count;
print("Number of messages in mailbox are " + str(nMessageCount));
nOccupiedSize = info.occupied_size;
print("Occupied size is " + str(nOccupiedSize));
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
capabilities = client.get_capabilities()
for val in capabilities:
print(val);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
uniqueId = "unique id of a message from server"
messageInfo = client.get_message_info(uniqueId)
if messageInfo is not None:
print(messageInfo.subject)
print(messageInfo.date)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
headers = client.get_message_headers(1)
for index, header in enumerate(headers):
print(header + " - ", end=" ")
print (headers.get(index))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
messageCount = client.get_message_count();
print("Total messages: " + str(messageCount))
#Create an instance of the MailMessage class and Retrieve message
for i in range(0,messageCount):
message = client.fetch_message(i+1)
print("From:" + str(message.from_address))
print("Subject:" + message.subject)
print(message.html_body);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client("pop.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
try:
# Save message to disk by message sequence number
client.save_message(1, "SaveToDiscWithoutParsing_out.eml")
client.dispose()
except Exception as ex:
print(str(ex))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = Pop3Client()
# Specify host, username and password, Port and SecurityOptions for your client
client.host = "pop.gmail.com"
client.username = "[email protected]"
client.password = "your.password"
client.port = 995
client.security_options = SecurityOptions.SSLEXPLICIT;
print("Connecting to POP3 server using SSL.")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage.load("Message.eml")
eml.from_address = "[email protected]"
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.forward("[email protected]", "[email protected]", eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = SmtpClient("smtp.gmail.com", 587, "username", "password")
client.security_options = SecurityOptions.AUTO
caps = []
caps = client.get_capabilities()
for str in caps:
print(str)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "New MailMessage created with Aspose.Email for Python"
eml.html_body = "<b>This line is in bold </b> while this is normal text"
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
eml.to.append(ae.MailAddress("[email protected]", "Recipient 2"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 3"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 4"))
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 587, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message1 = MailMessage("[email protected]", "[email protected]", "Sending Bulk Emails using Aspose.Email", "message1, how are you?")
message2 = MailMessage("[email protected]", "[email protected]", "Sending Bulk Emails using Aspose.Email", "message2, how are you?")
message3 = MailMessage("[email protected]", "[email protected]", "Sending Bulk Emails using Aspose.Email", "message3, how are you?")
manyMsg = MailMessageCollection()
manyMsg.append(message1)
manyMsg.append(message2)
manyMsg.append(message3)
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(manyMsg)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
#Create Appointment instance
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), eml.from_address, eml.to);
app.summary = "Release Meetting";
app.description = "Discuss for the next release"
eml.add_alternate_view(app.request_apointment())
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "Message with Plain Text Body"
eml.body = "This is plain text body."
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage.load("Message.eml")
eml.subject = "Send message as TNEF"
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.use_tnef= True
client.send(eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "Message with Alternate Text"
eml.is_body_html = True
eml.html_body = "<html><body>This is the <b>HTML</b>body</body></html>"
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
# Creates AlternateView to view an email message using the content specified in the //string
alternate = AlternateView.create_alternate_view_from_string("Alternate Text");
# Adding alternate text
eml.alternate_views.append(alternate)
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "Message with Html Body"
eml.is_body_html = True
eml.html_body = "<html><body>This is the <b>HTML</b>body</body></html>"
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
client = SmtpClient()
client.host = "smtp.gmail.com"
client.port = 587
client.username = "username"
client.password = "password"
client.security_options = SecurityOptions.SSLEXPLICIT
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Initialize MboxStorageWriter and pass the above stream to it
writer =MboxrdStorageWriter(dataDir + "ExampleMBox_out.mbox", False)
# Prepare a new message using the MailMessage class
message = MailMessage("[email protected]", "[email protected]", "Eml generated for Mbox", "added from Aspose.Email for Python")
message.is_draft = False
# Add this message to storage
writer.write_message(message)
# Close all related streams
writer.dispose();
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
reader = MboxrdStorageReader(dataDir + "ExampleMbox.mbox", False)
eml = reader.read_next_message()
# Read all messages in a loop
while (eml is not None):
print(reader.current_data_size)
eml.dispose();
eml = None
# Close the streams
reader.dispose();
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
reader = MboxrdStorageReader(dataDir + "ExampleMbox.mbox", False)
print("Total items in MBox file: " + str(reader.get_total_items_count()))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
reader = MboxrdStorageReader(dataDir + "ExampleMbox.mbox", False)
eml = reader.read_next_message()
# Read all messages in a loop
while (eml is not None):
# Manipulate message - show contents
print("Subject: " + eml.subject)
#Save this message in EML or MSG format
eml.save(eml.subject + "_out.eml", aspose.email.SaveOptions.default_eml)
eml.save(eml.subject + "_out.msg", aspose.email.SaveOptions.default_msg_unicode)
# Get the next message
eml = reader.read_next_message();
# Close the streams
reader.dispose();
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Create Appointment instance
attendees = MailAddressCollection()
attendees.append("[email protected]")
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "[email protected]", attendees);
app.summary = "Release Meetting";
app.description = "Discuss for the next release"
app.save(dataDir + "AppointmentInICSFormat_out.ics", AppointmentSaveFormat.ICS)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
ical = """BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN
VERSION:2.0
BEGIN:VEVENT
ATTENDEE;[email protected]:mailto:[email protected]
DTSTART:20130220T171439
DTEND:20130220T174439
DTSTAMP:20130220T161439Z
END:VEVENT
END:VCALENDAR"""
sender = "[email protected]"
recipient = "[email protected]"
message = MailMessage(sender, recipient, "", "")
av = AlternateView.create_alternate_view_from_string(ical, ContentType("text/calendar"))
message.alternate_views.append(av)
msg = MapiMessage.from_mail_message(message)
msg.save(dataDir + "draft_out.msg")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Create Appointment instance
attendees = MailAddressCollection()
attendees.append("[email protected]")
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "[email protected]", attendees);
app.summary = "Release Meetting";
app.description = "Discuss for the next release"
app.method_type = AppointmentMethodType.PUBLISH
message = MailMessage("[email protected]", "[email protected]", "", "")
message.add_alternate_view(app.request_apointment())
msg = MapiMessage.from_mail_message(message)
# Save the appointment as draft.
msg.save("DraftAppointmentRequest_out.msg")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Load Appointment instance
loadedAppointment = Appointment.load(dataDir + "AppointmentInICSFormat_out.ics")
print("Summary: " + loadedAppointment.summary)
print("Location: " + loadedAppointment.location)
print("Description: " + loadedAppointment.description)
print("Start date: " + str(loadedAppointment.start_date))
print("End date: " + str(loadedAppointment.end_date))
print("Organizer: " + loadedAppointment.organizer.address)
print("Attendees: " + loadedAppointment.attendees[0].address)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Load Appointment instance
reader = CalendarReader(dataDir + "US-Holidays.ics")
appointments = []
while reader.next_event():
appointments.append(reader.current)
print ("Total Appointments: " + str(len(appointments)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
location = "Room 5"
startDate = dt.datetime(2011, 12, 10, 10, 12, 11)
endDate = dt.date(2012, 11, 13)
organizer = ae.MailAddress("[email protected]", "Organizer")
attendees = ae.MailAddressCollection()
attendee1 = ae.MailAddress("[email protected]", "First attendee")
attendee2 = ae.MailAddress("[email protected]", "Second attendee")
attendee1.participation_status = ae.ParticipationStatus.ACCEPTED
attendee2.participation_status = ae.ParticipationStatus.DECLINED
attendees.append(attendee1)
attendees.append(attendee2)
target2 = Appointment(location, startDate, endDate, organizer, attendees)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
saveOptions = IcsSaveOptions()
saveOptions.action = AppointmentAction.CREATE
writer = CalendarWriter(dataDir + "WriteMultipleEventsToICS_out.ics", saveOptions)
attendees = MailAddressCollection()
attendees.append("[email protected]")
for i in range(10):
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "[email protected]", attendees)
app.description = "Test body " + str(i)
app.summary = "Test summary:" + str(i)
writer.write(app)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage("[email protected]", "[email protected]")
# Load an attachment
attachment = Attachment(dataDir + "1.txt");
# Add Multiple Attachment in instance of MailMessage class and Save message to disk
message.attachments.append(attachment);
message.add_attachment(Attachment(dataDir + "1.jpg"))
message.add_attachment(Attachment(dataDir + "1.doc"))
message.add_attachment(Attachment(dataDir + "1.rar"))
message.add_attachment(Attachment(dataDir + "1.pdf"))
message.save(dataDir + "AddEmailAttachments_out.msg", SaveOptions.default_msg_unicode)
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Declare message as MailMessage instance
eml = ae.MailMessage()
# Creates AlternateView to view an email message using the content specified in the //string
alternate = AlternateView.create_alternate_view_from_string("Alternate Text")
# Adding alternate text
eml.add_alternate_view(alternate)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MailMessage();
message.subject = "Creating Message with Friendly Email Address."
# A To address with a friendly name can also be specified like this
message.to.append(MailAddress("[email protected]", "Kyle Huang"))
# Specify Cc and Bcc email address along with a friendly name
message.cc.append(MailAddress("[email protected]", "Guangzhou Team"))
message.bcc.append(MailAddress("[email protected]", "Ammad ulHaq "))
message.save(dataDir + "MessageWithFrienlyName_out.eml", SaveOptions.default_eml)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "New MailMessage created with Aspose.Email for Python"
eml.html_body = "<b>This line is in bold </b> while this is normal text"
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
eml.to.append(ae.MailAddress("[email protected]", "Recipient 2"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 3"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 4"))
#Save generated EML in different formats to disc
eml.save(dataDir + "CreateNewMailMessage_out.eml")
eml.save(dataDir + "CreateNewMailMessage_out.msg", ae.SaveOptions.default_msg_unicode)
eml.save(dataDir + "message_out.msg", ae.SaveOptions.default_msg)
eml.save(dataDir + "message_out.mhtml", ae.SaveOptions.default_mhtml)
eml.save(dataDir + "message_out.html", ae.SaveOptions.default_html)
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Add by SMTP server in delivery emails
Received: from ip-123.56.99.216.dsl-cust.ca.inter.net ([216.99.56.123]) by Aspose.secureserver.net with MailEnable ESMTP; Thu, 22 Feb 2007 13:58:57 -0700
# Add by SMTP server in delivery emails
Return-Path: <[email protected]>
# Add by SMTP server in delivery emails
Received: from 195.120.225.20 (HELO mail.oikoscucine.it)
by aspose.com with esmtp (:1CYY+<LA*- *1WK@)
id Q8,/O/-.N83@7-9M
for [email protected]; Thu, 22 Feb 2007 20:58:51 +0300
From: "XYZ" <[email protected]>
To: <[email protected]>
Subject: For ABC
# Date will set the Date field, outlook will show this as
Date: Thu, 22 Feb 2007 20:58:51 +0300
Message-ID: <01c756c4$41b554d0$6c822ecf@dishonestyinsufferably>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0006_01C7569A.58DF4CD0"
X-Mailer: Microsoft Office Outlook, Build 11.0.5510
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Thread-Index: Aca6Q:=ES0M(9-=(<.<1.<Q9@QE6CD==
X-Read: 1
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage.load("EmailWithAttandEmbedded.eml")
# Save attachments from message
for index, att in enumerate(message.attachments):
if att.is_embedded_message:
print("Attachment is an embedded message")
else:
print("Attachment is not an embedded message")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage.load("EmailWithAttandEmbedded.eml")
# Print attachments information
for index, att in enumerate(message.attachments):
print(att.name)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create MailMessage instance by loading an Eml file
message = MailMessage.load(dataDir + "test.eml")
# Gets the sender info, recipient info, Subject, htmlbody and textbody
print("Subject: " + message.subject)
print("HtmlBody: " + message.html_body)
print("TextBody: " + message.body)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage.load("EmailWithAttandEmbedded.eml")
# Save attachments from message
for index, att in enumerate(message.attachments):
att.save(dataDir + att.name)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create MailMessage instance by loading an EML file
message = MailMessage.load(dataDir + "email-headers.eml");
print("\n\nheaders:\n\n")
# Print out all the headers
index = 0
for index, header in enumerate(message.headers):
print(header + " - ", end=" ")
print (message.headers.get(index))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
mailMessage = MailMessage.load(dataDir + "emlWithHeaders.eml");
decodedValue = mailMessage.headers.get_decoded_value("Thread-Topic")
print(decodedValue)
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Insert Header at Specific Location
eml = ae.MailMessage()
eml.headers.Insert("Received", "Value")
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = ae.MailMessage()
message.from_address = "[email protected]"
message.to.append(ae.MailAddress("[email protected]", "Receiver"))
message.subject = "Using MailMessage Features"
# Specify message date
message.date = datetime.datetime.now()
# Specify message priority
message.priority = ae.MailPriority.HIGH
# Specify message sensitivity
message.Sensitivity = ae.MailSensitivity.NORMAL
# Specify options for delivery notifications
message.DeliveryNotificationOptions = ae.DeliveryNotificationOptions.ON_SUCCESS
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage.load("EmailWithAttandEmbedded.eml")
message.linked_resources.remove_at(0, True)
message.alternate_views[0].linked_resources.clear(True)
message.save("RemoveLRTracesFromMessageBody_out.eml")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage("[email protected]", "[email protected]")
# Load an attachment
attachment = Attachment(dataDir + "1.txt");
# Add Multiple Attachment in instance of MailMessage class and Save message to disk
message.attachments.append(attachment)
print("Attachments count before removing: " + str(len(message.attachments)))
message.attachments.remove(attachment)
print("Attachments count after removing: " + str(len(message.attachments)))
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an Instance of MailMessage class
message = ae.MailMessage()
message.from_address = "[email protected]"
message.to.append(ae.MailAddress("[email protected]", "Receiver"))
message.subject = "Using MailMessage Features"
message.html_body = "<html><body>This is the Html body</body></html>"
message.DeliveryNotificationOptions = ae.DeliveryNotificationOptions.ON_SUCCESS
message.headers.add("Return-Receipt-To", "[email protected]")
message.Headers.add("Disposition-Notification-To", "[email protected]")
# Create an instance of SmtpClient Class and specify your mailing Host server, Username, Password and Port No
client = ae.clients.smtp.SmtpClient("smtp.gmail.com", 995, "username", "password")
try:
# Client.Send will send this message
client.send(message)
# Display ‘Message Sent’, only if message sent successfully
print("Message sent")
except:
print("Some Error Occured!")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage.load("EmailWithAttandEmbedded.eml")
# Save attachments from message
for index, att in enumerate(message.attachments):
print(att.headers.get("Content-Description"))
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
# Specify ReplyTo, From, To field, Cc and Bcc Addresses
eml.reply_to_list.Add("[email protected]")
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
eml.to.append(ae.MailAddress("[email protected]", "Recipient 2"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 3"))
eml.bcc.append(ae.MailAddress("[email protected]", "Recipient 4"))
# Specify Date, Message subject, XMailer, Secret Header, Save message to disc
eml.subject = "test mail"
eml.date = datetime.datetime(2006, 3, 6, 12, 00)
eml.xmailer = "Aspose.Email"
eml.headers.Add("secret-header", "mystery")
eml.save(dataDir + "SetEmailHeaders_out.msg", ae.SaveOptions.default_msg)
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Declare message as MailMessage instance
eml = ae.MailMessage()
# Specify HtmlBody
eml.html_body = "<html><body>This is the HTML body</body></html>"
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
eml = ae.MailMessage()
# Specify ReplyTo, From, To field, Cc and Bcc Addresses
eml.reply_to_list.Add("[email protected]")
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
eml.subject = "test mail"
eml.headers.Add("secret-header", "mystery")
client = ae.clients.smtp.SmtpClient("smtp.gmail.com", 995, "username", "password")
try:
# Client.Send will send this message
client.send(eml)
# Display ‘Message Sent’, only if message sent successfully
print("Message sent")
except:
print("Some Error Occured!")
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "New MailMessage created with Aspose.Email for Python"
eml.html_body = "<b>This line is in bold </b> while this is normal text"
eml.from_address = "[email protected]"
eml.to.append(ae.MailAddress("[email protected]", "Recipient 1"))
eml.to.append(ae.MailAddress("[email protected]", "Recipient 2"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 3"))
eml.cc.append(ae.MailAddress("[email protected]", "Recipient 4"))
# Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 587, "username", "password")
client.send(eml)
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create the appointment
calendar = MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
dt.datetime(2018, 6, 1, 21, 30, 0),
dt.datetime(2018, 6, 1, 21, 50, 0))
calendar.reminder_set= True
calendar.reminder_delta = 45 #45 min before start of event
calendar.reminder_file_parameter = "file://Alarm01.wav"
calendar.save(dataDir + "AddAudioReminderToCalendar_out.ics", AppointmentSaveFormat.ICS)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create the appointment
calendar = MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
dt.datetime(2018, 6, 1, 21, 30, 0),
dt.datetime(2018, 6, 1, 21, 50, 0))
calendar.reminder_set= True
calendar.reminder_delta = 45 #45 min before start of event
calendar.save(dataDir + "AddDisplayReminderToCalendar_out.ics", AppointmentSaveFormat.ICS)
calendar.save(dataDir + "AddDisplayReminderToCalendar_out.Msg", AppointmentSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage()
# Set from, to, subject and body properties
eml.from_address = "[email protected]";
eml.to.append("[email protected]");
eml.subject = "This is test message";
eml.body = "This is test body";
#Add attachments to MailMessage
eml.add_attachment(Attachment(dataDir + "1.jpg"))
eml.add_attachment(Attachment(dataDir + "1.doc"))
eml.add_attachment(Attachment(dataDir + "1.pdf"))
# Create an instance of the MapiMessage class and pass MailMessage as argument
outlookMsg = MapiMessage.from_mail_message(eml);
# Save the message (MSG) file
strMsgFile = "AddingMSGAttachments_out.msg"
outlookMsg.save(dataDir + strMsgFile);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("message.msg")
FollowUpManager.add_voting_button(message, "Indeed!")
message.save(dataDir + "AddVotingButtonToExistingMessage_out.msg")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
startDate = dt.datetime(2015, 4, 30, 10, 00, 00)
task = MapiTask("abc", "def", startDate, dt.datetime(2015, 4, 30, 11, 00, 00))
task.state = MapiTaskState.NOT_ASSIGNED
# Set the weekly recurrence
rec = MapiCalendarDailyRecurrencePattern()
rec.pattern_type = MapiCalendarRecurrencePatternType.DAY
rec.period = 1
rec.week_start_day = 0 #0 is for Sunday and so on. WeekStartDay=0
rec.occurrence_count = 0
task.recurrence = True
task.save(dataDir + "AsposeDaily_out.msg", TaskSaveFormat.MSG)
# Set the weekly recurrence
rec1 = MapiCalendarWeeklyRecurrencePattern()
rec1.pattern_type = MapiCalendarRecurrencePatternType.WEEK
rec1.period = 1
rec1.day_of_week = MapiCalendarDayOfWeek.WEDNESDAY
rec1.end_type = MapiCalendarRecurrenceEndType.NEVER_END
rec1.occurrence_count = 0
task.recurrence = rec1
task.save(dataDir + "AsposeWeekly_out.msg", TaskSaveFormat.MSG);
# Set the monthly recurrence
recMonthly = MapiCalendarMonthlyRecurrencePattern()
recMonthly.pattern_type = MapiCalendarRecurrencePatternType.MONTH
recMonthly.period = 1
recMonthly.end_type = MapiCalendarRecurrenceEndType.NEVER_END
recMonthly.day = 30
recMonthly.occurrence_count = 0
recMonthly.week_start_day = 0 #0 is for Sunday and so on. WeekStartDay=0
task.recurrence = recMonthly
task.save(dataDir + "AsposeMonthly_out.msg", TaskSaveFormat.MSG);
# Set the yearly recurrence
recYearly = MapiCalendarMonthlyRecurrencePattern()
recYearly.pattern_type = MapiCalendarRecurrencePatternType.MONTH
recYearly.end_type = MapiCalendarRecurrenceEndType.NEVER_END
recYearly.occurrence_count = 10
recYearly.period = 12
task.recurrence = recYearly
task.save(dataDir + "AsposeYearly_out.msg", TaskSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
task = MapiTask("To Do", "Just click and type to add new task", dt.datetime(2018, 6, 1, 21, 30, 0), dt.datetime(2018, 6, 4, 21, 30, 0))
task.reminder_set = True
task.reminder_time = dt.datetime(2018, 6, 1, 21, 30, 0)
task.reminder_file_parameter =dataDir + "file://Alarm01.wav"
task.save(dataDir + "AddReminderInformationToMapiTask_out.msg", TaskSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of the MapiMessage class
msg = MapiMessage("[email protected]","[email protected]; [email protected]","Test Subject","This is a body of message.")
options = MailConversionOptions()
options.convert_as_tnef = True
mail = msg.to_mail_message(options)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create the appointment
calendar = MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
dt.datetime(2018, 6, 1, 21, 30, 0),
dt.datetime(2018, 6, 1, 21, 50, 0))
calendar.save(dataDir + "CreateAndSaveCalendarItemsAsICS_out.ics", AppointmentSaveFormat.ICS)
calendar.save(dataDir + "CreateAndSaveCalendarItemsAsMSG_out.Msg", AppointmentSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
contact = MapiContact()
contact.name_info = MapiContactNamePropertySet("Bertha", "A.", "Buell")
contact.professional_info = MapiContactProfessionalPropertySet("Awthentikz", "Social work assistant")
contact.personal_info.personal_home_page = "B2BTies.com"
contact.physical_addresses.work_address.address = "Im Astenfeld 59 8580 EDELSCHROTT"
contact.electronic_addresses.email_1 = MapiContactElectronicAddress("Experwas", "SMTP", "[email protected]")
contact.telephones = MapiContactTelephonePropertySet("06605045265")
contact.mileage = "Some test mileage"
contact.billing = "Test billing information"
contact.other_fields.journal = True
contact.personal_info.children = []
contact.personal_info.children.append("child1")
contact.personal_info.children.append("child2")
contact.personal_info.children.append("child3")
contact.categories = ["category1", "category2", "category3"]
contact.other_fields.private = True
##contact.OtherFields.ReminderTime = new DateTime(2014, 1, 1, 0, 0, 55);
contact.other_fields.reminder_topic = "Test topic"
contact.other_fields.user_field_1 = "ContactUserField1"
contact.other_fields.user_field_2 = "ContactUserField2"
contact.other_fields.user_field_3 = "ContactUserField3"
contact.other_fields.user_field_4 = "ContactUserField4"
#Save the Contact in MSG format
contact.save(dataDir + "CreateAndSaveOutlookContact_out.msg",ContactSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
note3 = MapiNote()
note3.subject = "Blue color note"
note3.body = "This is a blue color note";
note3.color = NoteColor.YELLOW
note3.height = 500
note3.width = 500
note3.save(dataDir + "CreateAndSaveOutlookNote_out.msg", NoteSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage()
# Set from, to, subject and body properties
eml.from_address = "[email protected]";
eml.to.append("[email protected]");
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);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
task = MapiTask("To Do", "Just click and type to add new task", dt.datetime(2018, 6, 1, 21, 30, 0), dt.datetime(2018, 6, 4, 21, 30, 0))
task.percent_complete = 20
task.estimated_effort = 2000
task.actual_effort = 20
task.history = MapiTaskHistory.ASSIGNED
task.last_update = dt.datetime(2018, 6, 1, 21, 30, 0)
task.users.owner = "Darius"
task.users.last_assigner = "Harkness"
task.users.last_delegate = "Harkness"
task.users.ownership = MapiTaskOwnership.ASSIGNERS_COPY
task.companies = [ "company1", "company2", "company3" ]
task.categories = [ "category1", "category2", "category3" ]
task.mileage = "Some test mileage"
task.billing = "Test billing information"
task.users.delegator = "Test Delegator"
task.sensitivity = MapiSensitivity.PERSONAL
task.status = MapiTaskStatus.COMPLETE
task.estimated_effort = 5
task.save(dataDir + "CreatingAndSavingOutlookTask_out.msg", TaskSaveFormat.MSG)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage()
eml.is_draft = True
# Create an instance of the MapiMessage class and pass MailMessage as argument
outlookMsg = MapiMessage.from_mail_message(eml)
# Set RTF Body
outlookMsg.body_rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}\r\n{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\lang9\\f0\\fs22 This is RTF Body with this \\b bold \\b0 text.\\par\r\n}\r\n\0"
# Save the message (MSG) file
strMsgFile = "CreatingMSGFilesWithRtfBody_out.msg"
outlookMsg.save(dataDir + strMsgFile);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("message.msg")
FollowUpManager.add_voting_button(message, "Indeed!")
message.save(dataDir + "AddVotingButtonToExistingMessage_out.msg")
eml = MailMessage("[email protected]", "[email protected]", "Subject", "Body")
eml.is_draft = False
msg = MapiMessage.from_mail_message(eml)
options = FollowUpOptions()
options.voting_buttons = "Yes;No;Maybe;Exactly!"
FollowUpManager.set_options(msg, options)
msg.save(dataDir + "MapiMsgWithPoll.msg")
FollowUpManager.remove_voting_button(msg, "Exactly!");#Deleting a single button OR
FollowUpManager.clear_voting_buttons(msg) # Deleting all buttons from a MapiMessage
msg.save(dataDir + "MapiMsgWithPoll_out.msg")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("filename.msg")
for recipient in message.recipients:
print(recipient.recipient_track_status)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create the appointment
attendees = MailAddressCollection()
attendees.append("[email protected]")
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "[email protected]", attendees)
app.summary = "Release Meetting";
app.description = "Discuss for the next release"
app.attachments.append(Attachment("1.jpg"))
app.attachments.append(Attachment("1.doc"))
app.save("appWithAttachments_out.ics", AppointmentSaveFormat.ICS)
#Read the attachments from CIS
app2 = Appointment.load(dataDir + "appWithAttachments_out.ics")
print("Total attachments: " + str(len(app2.attachments)))
for att in app2.attachments:
print(att.name)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Load from file
msg = MapiMessage.from_file(dataDir + "message.msg")
# Access the MapiPropertyTag.PR_SUBJECT property
prop = msg.properties[MapiPropertyTag.SUBJECT]
# If the property is not found, check the MapiPropertyTag.PR_SUBJECT_W (which is a // Unicode peer of the MapiPropertyTag.PR_SUBJECT)
if prop is None:
prop = msg.properties[MapiPropertyTag.SUBJECT_W]
# Cannot found
if prop is None:
print("No property found!")
# Get the property data as string
subject = prop.get_string()
print("Subject:" + subject)
# Read internet code page property
prop = msg.properties[MapiPropertyTag.INTERNET_CPID]
if prop is not None:
print("CodePage:" + str(prop.get_long()))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("Contact.msg")
apiContact = message.to_mapi_message_item()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
contactReadFromFile = MapiContact.from_vcard(dataDir + "Contact.vcf", "UTF-8")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
VCardContact.load(dataDir + "Contact.vcf")
apiContact = MapiContact.from_vcard(dataDir + "Contact.vcf")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MapiMessage from file
msg = MapiMessage.from_file(dataDir + "CreatingAndSavingOutlookMessages_out.msg")
# Get subject
print("Subject: " + msg.subject)
# Get from address
print("From: " + msg.sender_email_address)
# Get body
print("Body: " + msg.body)
# Get recipients information
print("Recipients Count: " + str(len(msg.recipients)))
# Get Attachments information
print ("Attachments Count:" + str(len(msg.attachments)))
# Print attachments information
for index, att in enumerate(msg.attachments):
if att.object_data is not None:
print(att.display_name)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage.load(dataDir + "sample.eml", EmlLoadOptions())
options = MapiConversionOptions.unicode_format
options.preserve_embedded_message_format = True
# Create an instance of the MapiMessage class and pass MailMessage as argument
outlookMsg = MapiMessage.from_mail_message(eml, options)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
note = MapiMessage.from_file(dataDir + "CreateAndSaveOutlookNote_out.msg")
note2 = note.to_mapi_message_item()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("MessageWithVotingResponded.msg")
buttons = FollowUpManager.get_voting_buttons(message)
for button in buttons:
print(button)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("MessageWithVotingResponded.msg")
# This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category)
options = FollowUpManager.get_options(message)
# Voting buttons will be introduced as a string with semi-column as a separator
votingButtons = options.voting_buttons
print(votingButtons)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
msg = MapiMessage.from_file(dataDir + "AddVotingButtonToExistingMessage.msg");
for recipient in msg.recipients:
print("Recipient: {0}".format(recipient.display_name))
#get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
print("Response: {0}".format(recipient.properties[MapiPropertyTag.RECIPIENT_AUTORESPONSE_PROP_RESPONSE].get_string()))
#Get the PR_RECIPIENT_TRACKSTATUS_TIME property
mt = recipient.properties[MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME]
if mt is not None:
mt_value = mt.get_date_time()
print("Response time: {}".format(mt_value))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
msg = MapiMessage.from_file("Contact.msg")
op = MailConversionOptions()
eml = msg.to_mail_message(op)
#Prepare the MHT format options
mhtSaveOptions = MhtSaveOptions()
mhtSaveOptions.check_body_content_encoding = True
mhtSaveOptions.preserve_original_boundaries = True
formatOp = MhtFormatOptions.WRITE_HEADER | MhtFormatOptions.RENDER_VCARD_INFO
mhtSaveOptions.rendered_contact_fields = ContactFieldsSet.NAME_INFO | ContactFieldsSet.PERSONAL_INFO | ContactFieldsSet.TELEPHONES | ContactFieldsSet.EVENTS
mhtSaveOptions.mht_format_options = formatOp
eml.save(dataDir + "RenderingContactInformationToMhtml_out.mhtml", mhtSaveOptions)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of the MapiMessage class
msg = MapiMessage("[email protected]","[email protected]; [email protected]","Test Subject","This is a body of message.")
msg.save_as_template("SaveMsgAsTemplate_out.msg");
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of the MapiMessage class
outlookMsg = MapiMessage()
# Set Message Body
outlookMsg.body = "Message created with MapiMessage in draft mode."
#Set the Unsent flag
outlookMsg.set_message_flags(MapiMessageFlags.UNSENT)
# Save the message (MSG) file
strMsgFile = "SavingMessageInDraftStatus_out.msg"
outlookMsg.save(dataDir + strMsgFile);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = MailMessage.load("CreatingAndSavingOutlookMessages_out.msg");
options = MapiConversionOptions()
options.use_body_compression = True
ae_mapi = MapiMessage.from_mail_message(eml, options);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
def long_to_mapi_bytes(x):
return x.to_bytes(8, 'little')
# http://support.microsoft.com/kb/167296
# How To Convert a UNIX time_t to a Win32 FILETIME or SYSTEMTIME
EPOCH_AS_FILETIME = 116444736000000000 # January 1, 1970 as MS file time
HUNDREDS_OF_NANOSECONDS = 10000000
class FakeUTC(tzinfo):
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return timedelta(0)
utc = FakeUTC()
def dt_to_filetime(dt):
if (dt.tzinfo is None) or (dt.tzinfo.utcoffset(dt) is None):
dt = dt.replace(tzinfo=utc)
ft = EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)
return ft + (dt.microsecond * 10)
def date_to_mapi_bytes(dt):
ft = dt_to_filetime(dt)
return long_to_mapi_bytes(ft)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Setting MAPI Properties sample
msg = MapiMessage("[email protected]", "[email protected]", "This is subject", "This is body")
msg.set_property(MapiProperty(MapiPropertyTag.SENDER_ADDRTYPE, bytes("EX", "utf-8")))
recipientTo = msg.recipients[0]
propAddressType = MapiProperty(MapiPropertyTag.RECEIVED_BY_ADDRTYPE, bytes("MYFAX", "utf-8"))
recipientTo.set_property(propAddressType);
faxAddress = "My Fax User@/FN=fax#/VN=voice#/CO=My Company/CI=Local"
propEmailAddress = MapiProperty(MapiPropertyTag.RECEIVED_BY_EMAIL_ADDRESS, bytes(faxAddress, "utf-8"))
recipientTo.set_property(propEmailAddress)
msg.set_message_flags(MapiMessageFlags.UNSENT | MapiMessageFlags.FROMME)
msg.set_property( MapiProperty(MapiPropertyTag.RTF_IN_SYNC, long_to_mapi_bytes(1)) )
# DateTime property
modification_date = datetime(2013, 9, 11)
prop = MapiProperty(MapiPropertyTag.LAST_MODIFICATION_TIME, date_to_mapi_bytes(modification_date))
msg.set_property(prop)
msg.save("SetMapiProperties_out.msg")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "SampleContacts_out.pst")
folderInfo = pst.get_predefined_folder(StandardIpmFolder.CONTACTS)
messageInfoCollection = folderInfo.get_contents()
for messageInfo in messageInfoCollection:
# Get the contact information
mapi = pst.extract_message(messageInfo)
contact = mapi.to_mapi_message_item()
# Display some contents on screen
print("Name: " + contact.name_info.display_name)
#Save to disc in MSG Format
if contact.name_info.display_name is not None:
contact.save(dataDir + "Contacts\\" + contact.name_info.display_name + "_out.msg")
contact.save(dataDir + "Contacts\\" + contact.name_info.display_name + "_out.vcf", ContactSaveFormat.VCARD)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
personalStorage = PersonalStorage.create(dataDir + "AddFilesToPst_out.pst", FileFormatVersion.UNICODE)
folder = personalStorage.root_folder.add_sub_folder("Files")
folder.add_file(dataDir + "FileToBeAddedToPST.txt", "")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create the appointment
appointment = MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
dt.datetime(2018, 6, 1, 21, 30, 0),
dt.datetime(2018, 6, 1, 21, 50, 0))
# Create the meeting
attendees = MapiRecipientCollection()
attendees.add("[email protected]", "Renee A. Jones", MapiRecipientType.TO)
attendees.add("[email protected]", "Szollosy Liza", MapiRecipientType.TO)
meeting = MapiCalendar(
"Meeting Room 3 at Office Headquarters",
"Meeting",
"Please confirm your availability.",
dt.datetime(2018, 6, 1, 21, 30, 0),
dt.datetime(2018, 6, 1, 21, 50, 0),
"[email protected]",
attendees
)
os.remove(dataDir + "AddMapiCalendarToPST_out.pst")
personalStorage = PersonalStorage.create(dataDir + "AddMapiCalendarToPST_out.pst", FileFormatVersion.UNICODE)
calFolder = personalStorage.create_predefined_folder("AsposeCalendar", StandardIpmFolder.APPOINTMENTS)
calFolder.add_mapi_message_item(appointment)
calFolder.add_mapi_message_item(meeting)
personalStorage.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create three Notes
note1 = MapiNote()
note1.subject = "Yellow color note"
note1.body = "This is a yellow color note"
note2 = MapiNote()
note2.subject = "Pink color note"
note2.body = "This is a pink color note"
note2.color = NoteColor.PINK
note3 = MapiNote()
note2.subject = "Blue color note";
note2.body = "This is a blue color note";
note2.color = NoteColor.BLUE
note3.height = 500
note3.width = 500
personalStorage = PersonalStorage.create(dataDir + "AddMapiNoteToPST_out.pst", FileFormatVersion.UNICODE)
notesFolder = personalStorage.create_predefined_folder("Tasks", StandardIpmFolder.NOTES)
notesFolder.add_mapi_message_item(note1)
notesFolder.add_mapi_message_item(note2)
notesFolder.add_mapi_message_item(note3)
personalStorage.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
task = MapiTask("To Do", "Just click and type to add new task", dt.datetime.now(), dt.datetime.today() + timedelta(days=3))
task.percent_complete = 20
task.estimated_effort = 2000
task.actual_effort = 20
task.history = MapiTaskHistory.ASSIGNED
task.last_update = dt.datetime.now()
task.users.owner = "Darius"
task.users.last_assigner = "Harkness"
task.users.last_delegate = "Harkness";
task.users.ownership = MapiTaskOwnership.ASSIGNERS_COPY
personalStorage = PersonalStorage.create(dataDir + "AddMapiTaskToPST_out.pst", FileFormatVersion.UNICODE)
tasksFolder = personalStorage.create_predefined_folder("Tasks", StandardIpmFolder.TASKS)
tasksFolder.add_mapi_message_item(task)
personalStorage.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
sourcePst = PersonalStorage.from_file(dataDir + "Outlook.pst")
# Add new folder "Inbox"
sourceFolder = sourcePst.root_folder.get_sub_folder("Inbox")
destPst = PersonalStorage.create("DestinationPst_out.pst", FileFormatVersion.UNICODE)
# Add new folder "Inbox"
destFolder = destPst.root_folder.add_sub_folder("Inbox")
sourceMsgs = sourceFolder.get_contents()
destFolder.add_messages(sourceFolder.enumerate_mapi_messages())
#Verify that the messages have been added to the destination PST
print(str(destFolder.content_count))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.create(dataDir + "AddMessagesToPst_out.pst", FileFormatVersion.UNICODE)
# Add new folder "Inbox"
inboxFolder = pst.root_folder.add_sub_folder("Inbox");
# Add message to Inbox Folder
inboxFolder.add_message(MapiMessage.from_file(dataDir + "MapiMsgWithPoll.msg"))
pst.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "PstWithPython_out.pst")
folder = pst.root_folder.get_sub_folder("Inbox")
folder.change_container_class("IPF.Note")
pst.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "PersonalStorageFile.ost")
# Get the format of the file
pst.save_as(dataDir + "ConvertOSTToPst_out.pst", FileFormat.PST)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
displayName1 = "Sebastian Wright"
email1 = "[email protected]"
displayName2 = "Wichert Kroos"
email2 = "[email protected]"
os.remove(dataDir + "CreateDistributionListInPST_out.pst")
personalStorage = PersonalStorage.create(dataDir + "CreateDistributionListInPST_out.pst", FileFormatVersion.UNICODE)
contactFolder = personalStorage.create_predefined_folder("Contacts", StandardIpmFolder.CONTACTS)
# Create contacts
strEntryId1 = contactFolder.add_mapi_message_item(MapiContact(displayName1, email1))
strEntryId2 = contactFolder.add_mapi_message_item( MapiContact(displayName2, email2))
member1 = MapiDistributionListMember(displayName1, email1)
member1.entry_id_type = MapiDistributionListEntryIdType.CONTACT
member1.entry_id = base64.b64decode( bytes(strEntryId1, "utf-8") )
member2 = MapiDistributionListMember(displayName2, email2)
member2.entry_id_type = MapiDistributionListEntryIdType.CONTACT
member2.entry_id = base64.b64decode( bytes(strEntryId1, "utf-8") )
members = MapiDistributionListMemberCollection()
members.append(member1)
members.append(member2)
distribution_list = MapiDistributionList("Contact list", members)
distribution_list.body = "Distribution List Body"
distribution_list.subject = "Sample Distribution List using Aspose.Email"
# Add distribution list to PST
contactFolder.add_mapi_message_item(distribution_list);
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create three Contacts
contact1 = MapiContact("Sebastian Wright", "[email protected]")
contact2 = MapiContact("Wichert Kroos", "[email protected]", "Grade A Investment")
contact3 = MapiContact("Christoffer van de Meeberg", "[email protected]", "Krauses Sofa Factory", "046-630-4614046-630-4614")
# Contact 4
contact4 = MapiContact()
contact4.name_info = MapiContactNamePropertySet("Margaret", "J.", "Tolle")
contact4.personal_info.gender = MapiContactGender.FEMALE
contact4.professional_info = MapiContactProfessionalPropertySet("Adaptaz", "Recording engineer")
contact4.physical_addresses.work_address.address = "4 Darwinia Loop EIGHTY MILE BEACH WA 6725"
contact4.electronic_addresses.email_1 = MapiContactElectronicAddress("Hisen1988", "SMTP", "[email protected]")
contact4.telephones.business_telephone_number = "(08)9080-1183"
contact4.telephones.mobile_telephone_number = "(925)599-3355(925)599-3355"
# Contact #5
contact5 = MapiContact()
contact5.name_info = MapiContactNamePropertySet("Matthew", "R.", "Wilcox");
contact5.personal_info.gender = MapiContactGender.MALE;
contact5.professional_info = MapiContactProfessionalPropertySet("Briazz", "Psychiatric aide");
contact5.physical_addresses.work_address.address = "Horner Strasse 12 4421 SAASS";
contact5.telephones.business_telephone_number = "0650 675 73 300650 675 73 30";
contact5.telephones.home_telephone_number = "(661)387-5382(661)387-5382";
# Contact #6
contact6 = MapiContact();
contact6.name_info = MapiContactNamePropertySet("Bertha", "A.", "Buell");
contact6.professional_info = MapiContactProfessionalPropertySet("Awthentikz", "Social work assistant");
contact6.personal_info.personal_home_page = "B2BTies.com";
contact6.physical_addresses.work_address.address = "Im Astenfeld 59 8580 EDELSCHROTT";
contact6.electronic_addresses.email_1 = MapiContactElectronicAddress("Experwas", "SMTP", "[email protected]");
contact6.telephones = MapiContactTelephonePropertySet("06605045265");
personalStorage = PersonalStorage.create(dataDir + "SampleContacts_out.pst", FileFormatVersion.UNICODE)
contactFolder = personalStorage.create_predefined_folder("Contacts", StandardIpmFolder.CONTACTS)
contactFolder.add_mapi_message_item(contact1)
contactFolder.add_mapi_message_item(contact2);
contactFolder.add_mapi_message_item(contact3);
contactFolder.add_mapi_message_item(contact4);
contactFolder.add_mapi_message_item(contact5);
contactFolder.add_mapi_message_item(contact6);
personalStorage.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
journal =MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call")
journal.start_time = dt.datetime.now();
journal.end_time = dt.datetime.today() + timedelta(hours=1)
personalStorage = PersonalStorage.create(dataDir + "CreateNewMapiJournalAndAddToPST_out.pst", FileFormatVersion.UNICODE)
tasksFolder = personalStorage.create_predefined_folder("Journal", StandardIpmFolder.JOURNAL)
tasksFolder.add_mapi_message_item(journal)
personalStorage.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.create(dataDir + "PstWithPython_out.pst", FileFormatVersion.UNICODE)
# Add new folder "Inbox"
pst.root_folder.add_sub_folder("Inbox");
pst.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "Outlook.pst")
# Get the format of the file
folder = pst.get_predefined_folder(StandardIpmFolder.INBOX)
print("Total messges count in folder: " + str(len(folder.get_contents())))
# Create instance of PersonalStorageQueryBuilder
queryBuilder = PersonalStorageQueryBuilder()
queryBuilder.subject.contains("Microsoft")
messages = folder.get_contents(queryBuilder.get_query());
print("No. of Messages as per specified criterion: " + str(len(messages)))
deleteList = []
for messageInfo in messages:
deleteList.append(messageInfo.entry_id_string)
folder.delete_child_items(deleteList)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "Outlook.pst")
# Get the format of the file
folder = pst.get_predefined_folder(StandardIpmFolder.SENT_ITEMS)
print("Total messges count in folder: " + str(len(folder.get_contents())))
#Delete First Item
msgsColl = folder.get_contents()
msgInfo = msgsColl[0]
folder.delete_child_item(msgInfo.entry_id)
print("Total messges count in folder after deletion: " + str(len(folder.get_contents())))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
personalStorage = PersonalStorage.from_file(dataDir + "Outlook.pst")
folderInfoCollection = personalStorage.root_folder.get_sub_folders()
for folderInfo in folderInfoCollection:
print("Folder: " + folderInfo.display_name)
print("Total Items: " + str(folderInfo.content_count))
print("Total Unread Items: " + str(folderInfo.content_unread_count))
print("----------------------")
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "Outlook.pst")
# Get the format of the file
inbox = pst.root_folder.get_sub_folder("Inbox")
print("Total messges count in Inbox folder: " + str(len(inbox.get_contents())))
# Extracts messages starting from 3rd index top and extract total 100 messages
messagesColl = inbox.get_contents(3, 5)
print("Total Messages: " + str(len(messagesColl)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Read PST file and recursively list its contents
pst = PersonalStorage.from_file(dataDir + "Outlook.pst")
folderInfo = pst.root_folder
DisplayFolderContents(folderInfo, pst)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
personalStorage = PersonalStorage.from_file(dataDir + "test.pst")
# Get the format of the file
inbox = personalStorage.root_folder.get_sub_folder("Inbox")
deleted = personalStorage.get_predefined_folder(StandardIpmFolder.DELETED_ITEMS)
subfolder = inbox.get_sub_folder("SubInbox")
# Move folder and message to the Deleted Items
personalStorage.move_item(subfolder, deleted)
contents = subfolder.get_contents()
personalStorage.move_item(contents[0], deleted)
# Move all inbox subfolders and subfolder contents to the Deleted Items
inbox.move_subfolders(deleted)
subfolder.move_contents(deleted)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "PersonalStorageFile.ost")
# Get the format of the file
print("File Format of OST: " + str(pst.format))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
personalStorage = PersonalStorage.from_file(dataDir + "Outlook.pst")
for folder in personalStorage.root_folder.get_sub_folders():
for messageInfo in folder.enumerate_messages():
folderInfo = personalStorage.get_parent_folder(messageInfo.entry_id)
print(folderInfo.display_name)
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
personalStorage = PersonalStorage.from_file(dataDir + "AddMapiCalendarToPST_out.pst")
calFolder = personalStorage.get_predefined_folder(StandardIpmFolder.APPOINTMENTS)
print("Total items: " + str(calFolder.content_count))
for messageInfo in calFolder.get_contents():
calendar = personalStorage.extract_message(messageInfo).to_mapi_message_item()
print(calendar.subject)
calendar.save(dataDir + calendar.subject + "_out.ics")
personalStorage.dispose()
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "Outlook.pst")
# Get the format of the file
folder = pst.root_folder.get_sub_folder("Inbox")
print("Total messges count in folder: " + str(len(folder.get_contents())))
# Create instance of PersonalStorageQueryBuilder
queryBuilder = PersonalStorageQueryBuilder()
queryBuilder.from_address.contains("saqib")
messages = folder.get_contents(queryBuilder.get_query());
print("No. of Messages without Ignore Case specified: " + str(len(messages)))
queryBuilder = PersonalStorageQueryBuilder()
queryBuilder.from_address.contains("saqib", True)
messages = folder.get_contents(queryBuilder.get_query())
print("No. of Messages with Ignore Case specified: " + str(len(messages)))
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
pst = PersonalStorage.from_file(dataDir + "test.pst")
# Get the format of the file
folder = pst.root_folder.get_sub_folder("Inbox")
print("Total messges count in folder: " + str(len(folder.get_contents())))
# Create instance of PersonalStorageQueryBuilder
queryBuilder = PersonalStorageQueryBuilder()
queryBuilder.from_address.contains("saqib", True)
messages = folder.get_contents(queryBuilder.get_query())
print("No. of Messages with specified criterion: " + str(len(messages)))
changeList = []
for messageInfo in messages:
changeList.append(messageInfo.entry_id_string)
# Compose the new properties
updatedProperties = MapiPropertyCollection()
updatedProperties.Add(MapiPropertyTag.PR_SUBJECT_W, new MapiProperty(MapiPropertyTag.PR_SUBJECT_W, Encoding.Unicode.GetBytes("New Subject")));
updatedProperties.Add(MapiPropertyTag.PR_IMPORTANCE, new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((long)2)));
# update messages having From = "[email protected]" with new properties
inbox.ChangeMessages(changeList, updatedProperties);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment