Skip to content

Commit d399fb8

Browse files
committed
Aspose.Email Java for Jython
1 parent 9aafec2 commit d399fb8

File tree

43 files changed

+1039
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1039
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import SaveOptions
4+
5+
class Converter:
6+
7+
def __init__(self):
8+
9+
# Loading EML, Saving to MSG
10+
self.convert_eml_to_msg()
11+
12+
def convert_eml_to_msg(dataDir):
13+
14+
dataDir = Settings.dataDir + 'ProgrammingEmail/Converter/'
15+
16+
# Initialize and Load an existing EML file by specifying the MessageFormat
17+
mailMessage = MailMessage()
18+
eml = mailMessage.load(dataDir + "Message.eml")
19+
20+
# Save the Email message to disk in Unicode format
21+
saveOptions= SaveOptions
22+
eml.save(dataDir + "AnEmail.msg", saveOptions.getDefaultMsgUnicode())
23+
24+
# Display Status
25+
print "Converted email to msg successfully."
26+
27+
if __name__ == '__main__':
28+
Converter()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import MailAddress
4+
from com.aspose.email import MailMessageSaveType
5+
6+
class CreateNewEmail:
7+
8+
def __init__(self):
9+
10+
dataDir = Settings.dataDir + 'ProgrammingEmail/CreateNewEmail/'
11+
12+
# Create a instance of MailMessage class
13+
message = MailMessage()
14+
15+
# Set subject of the message
16+
message.setSubject("New message created by Aspose.Email for Java")
17+
18+
mail_address = MailAddress
19+
20+
# Set Html body
21+
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" +
22+
"<font color=blue>This line is in blue color</font>")
23+
24+
# Set sender information
25+
message.setFrom(MailAddress("[email protected]", "Sender Name", False))
26+
27+
# Add TO recipients
28+
message.getTo().add(MailAddress("[email protected]", "Recipient 1", False))
29+
message.getTo().add(MailAddress("[email protected]", "Recipient 2", False))
30+
31+
# Add CC recipients
32+
message.getCC().add(MailAddress("[email protected]", "Recipient 3", False))
33+
message.getCC().add(MailAddress("[email protected]", "Recipient 4", False))
34+
35+
# Save message in EML and MSG formats
36+
mail_message_save_type = MailMessageSaveType()
37+
message.save(dataDir + "Message.eml", mail_message_save_type.getEmlFormat())
38+
message.save(dataDir + "Message.msg", mail_message_save_type.getOutlookMessageFormat())
39+
# Display Status
40+
print "Created email messages Successfully."
41+
42+
if __name__ == '__main__':
43+
CreateNewEmail()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import MailAddress
4+
from com.aspose.email import MessageFormat
5+
from java.util import TimeZone
6+
from java.util import Calendar
7+
8+
9+
class CustomizeEmailHeaders:
10+
11+
def __init__(self):
12+
13+
dataDir = Settings.dataDir + 'ProgrammingEmail/CustomizeEmailHeaders/'
14+
15+
# Create a instance of MailMessage class
16+
message = MailMessage()
17+
18+
# Set subject of the message
19+
message.setSubject("New message created by Aspose.Email for Java")
20+
21+
# Set Html body
22+
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" +
23+
"<font color=blue>This line is in blue color</font>")
24+
25+
# Set sender information
26+
message.setFrom(MailAddress("[email protected]", "Sender Name", False))
27+
28+
# Add TO recipients
29+
message.getTo().add(MailAddress("[email protected]", "Recipient 1", False))
30+
31+
# Message subject
32+
message.setSubject("Customizing Email Headers")
33+
34+
# Specify Date
35+
timeZone=TimeZone()
36+
calendar=Calendar()
37+
calendar = calendar.getInstance(timeZone.getTimeZone("GMT"))
38+
39+
date = calendar.getTime()
40+
message.setDate(date)
41+
42+
# Specify XMailer
43+
message.setXMailer("Aspose.Email")
44+
45+
# Specify Secret Header
46+
message.getHeaders().add("secret-header", "mystery")
47+
48+
# Save message to disc
49+
messageFormat=MessageFormat()
50+
message.save(dataDir + "MsgHeaders.msg", messageFormat.getMsg())
51+
52+
# Display Status
53+
print "Customized message headers Successfully."
54+
55+
if __name__ == '__main__':
56+
CustomizeEmailHeaders()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
4+
class ExtractEmailHeaders:
5+
6+
def __init__(self):
7+
8+
dataDir = Settings.dataDir + 'ProgrammingEmail/ExtractEmailHeaders/'
9+
10+
# Initialize and Load an existing EML file by specifying the MessageFormat
11+
mailMessage=MailMessage()
12+
13+
message = mailMessage.load(dataDir + "Message.eml")
14+
15+
print "Printing all Headers:"
16+
17+
# Print out all the headers
18+
i=0
19+
while (i < message.getHeaders().getCount()):
20+
print message.getHeaders().get(i)
21+
i += 1
22+
23+
24+
if __name__ == '__main__':
25+
ExtractEmailHeaders()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import MessageFormat
4+
5+
class GetEmailInfo:
6+
7+
def __init__(self):
8+
9+
dataDir = Settings.dataDir + 'ProgrammingEmail/GetEmailInfo/'
10+
11+
# Create MailMessage instance by loading an Eml file
12+
message_format = MessageFormat
13+
mailMessage=MailMessage()
14+
message = mailMessage.load(dataDir + "Message.eml")
15+
16+
print "From: "
17+
print message.getFrom()
18+
19+
print "To: "
20+
print message.getTo()
21+
22+
print "Subject: "
23+
print message.getSubject()
24+
25+
print "HtmlBody: "
26+
print message.getHtmlBody()
27+
28+
print "TextBody: "
29+
print message.getTextBody()
30+
31+
32+
if __name__ == '__main__':
33+
GetEmailInfo()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import MailAddress
4+
from com.aspose.email import Attachment
5+
from com.aspose.email import MessageFormat
6+
7+
class ManageAttachments:
8+
9+
def __init__(self):
10+
11+
self.add_attachments()
12+
13+
def add_attachments(dataDir):
14+
15+
dataDir = Settings.dataDir + 'ProgrammingEmail/ManageAttachments/'
16+
17+
# Create a instance of MailMessage class
18+
message =MailMessage()
19+
20+
# Set subject of the message
21+
message.setSubject("New message created by Aspose.Email for Java")
22+
23+
mail_address = MailAddress
24+
25+
# Set Html body
26+
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" +
27+
"<font color=blue>This line is in blue color</font>")
28+
29+
# Set sender information
30+
message.setFrom(MailAddress("[email protected]", "Sender Name", False))
31+
32+
# Add TO recipients
33+
message.getTo().add(MailAddress("[email protected]", "Recipient 1", False))
34+
35+
# Adding attachment
36+
# Load an attachment
37+
38+
attachment = Attachment(dataDir + "1.txt")
39+
40+
# Add attachment in instance of MailMessage class
41+
message.addAttachment(attachment)
42+
43+
# Save message to disc
44+
messageFormat=MessageFormat()
45+
message.save(dataDir + "Add-Attachment.msg", messageFormat.getMsg())
46+
47+
# Display Status
48+
print "Added attachment successfully."
49+
50+
51+
if __name__ == '__main__':
52+
ManageAttachments()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import MailAddress
4+
from com.aspose.email import MapiMessage
5+
from com.aspose.email import MapiMessageFlags
6+
7+
class SaveMessageAsDraft:
8+
9+
def __init__(self):
10+
11+
dataDir = Settings.dataDir + 'ProgrammingEmail/SaveMessageAsDraft/'
12+
13+
# Create a instance of MailMessage class
14+
message = MailMessage()
15+
16+
# Set subject of the message
17+
message.setSubject("New message created by Aspose.Email for Java")
18+
19+
mail_address = MailAddress
20+
21+
# Set Html body
22+
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" +
23+
"<font color=blue>This line is in blue color</font>")
24+
25+
# Set sender information
26+
message.setFrom(MailAddress("[email protected]", "Sender Name", False))
27+
28+
# Add TO recipients
29+
message.getTo().add(MailAddress("[email protected]", "Recipient 1", False))
30+
message.getTo().add(MailAddress("[email protected]", "Recipient 2", False))
31+
32+
# Create an instance of MapiMessage and load the MailMessag instance into it
33+
mapiMessage=MapiMessage()
34+
mapi_msg = mapiMessage.fromMailMessage(message)
35+
36+
# Set the MapiMessageFlags as UNSENT and FROMME
37+
mapi_message_flags = MapiMessageFlags()
38+
39+
# Save the MapiMessage to disk
40+
mapi_msg.save(dataDir + "New-Draft.msg")
41+
42+
# Display Status
43+
print "Draft saved Successfully."
44+
45+
46+
if __name__ == '__main__':
47+
SaveMessageAsDraft()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import MailMessage
3+
from com.aspose.email import MailAddressCollection
4+
from com.aspose.email import MailMessageSaveType
5+
6+
class UpdateEmail:
7+
8+
def __init__(self):
9+
10+
dataDir = Settings.dataDir + 'ProgrammingEmail/UpdateEmail/'
11+
12+
# Initialize and Load an existing MSG file by specifying the MessageFormat
13+
mailMessage=MailMessage()
14+
email = mailMessage.load(dataDir + "Message.msg")
15+
16+
# Initialize a String variable to get the Email Subject
17+
subject = email.getSubject()
18+
19+
# Append some more information to Subject
20+
subject = subject + " This text is added to the existing subject"
21+
22+
# Set the Email Subject
23+
email.setSubject('This text is added to the existing subject')
24+
25+
# Initialize a String variable to get the Email's HTML Body
26+
body = email.getHtmlBody()
27+
28+
# Apppend some more information to the Body variable
29+
body = body + "<br> This text is added to the existing body"
30+
31+
# Set the Email Body
32+
email.setHtmlBody(body)
33+
34+
# Initialize MailAddressCollection object
35+
contacts = MailAddressCollection()
36+
37+
# Retrieve Email's TO list
38+
contacts = email.getTo()
39+
40+
# Add another email address to collection
41+
contacts.add("[email protected]")
42+
43+
# Set the collection as Email's TO list
44+
email.setTo(contacts)
45+
46+
# Initialize MailAddressCollection
47+
contacts = MailAddressCollection()
48+
49+
# Retrieve Email's CC list
50+
contacts = email.getCC()
51+
52+
# Add another email address to collection
53+
contacts.add("[email protected]")
54+
55+
# Set the collection as Email's CC list
56+
email.setCC(contacts)
57+
58+
# Save the Email message to disk by specifying the MessageFormat
59+
mailMessageSaveType=MailMessageSaveType
60+
email.save(dataDir + "UpdateMessage.msg", mailMessageSaveType.getOutlookMessageFormat())
61+
62+
# Display Status
63+
print "Updated email message Successfully."
64+
65+
66+
if __name__ == '__main__':
67+
UpdateEmail()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from asposeemail import Settings
2+
from com.aspose.email import PersonalStorage
3+
from com.aspose.email import FileFormatVersion
4+
from com.aspose.email import StandardIpmFolder
5+
6+
class AddFileToPST:
7+
8+
def __init__(self):
9+
10+
dataDir = Settings.dataDir + 'ProgrammingOutlook/WorkingWithOutlookPersonalStorage/AddFileToPST/'
11+
12+
personalStorage=PersonalStorage()
13+
fileFormatVersion=FileFormatVersion
14+
pst = personalStorage.create(dataDir + "AddFile1.pst", fileFormatVersion.Unicode)
15+
16+
standardIpmFolder=StandardIpmFolder
17+
fi = pst.createPredefinedFolder("Inbox", standardIpmFolder.Inbox)
18+
19+
fi.addFile(dataDir + "Report.xlsx", "IPM.Document.Excel.Sheet.8")
20+
21+
pst.dispose()
22+
23+
print "Added file to PST"
24+
25+
26+
if __name__ == '__main__':
27+
AddFileToPST()

0 commit comments

Comments
 (0)