Hi Rajiv,
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>public static void <span style=“font-size: 9pt; font-family: “Courier New”;”>Email_844365()
{
String fileName = (<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Sample.msg”<span style=“font-size: 9pt; font-family: “Courier New”;”>);
MapiMessage message = MapiMessage.fromFile(fileName);
MapiAttachmentCollection attachments
= message.getAttachments();
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>for <span style=“font-size: 9pt; font-family: “Courier New”;”>(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>int <span style=“font-size: 9pt; font-family: “Courier New”;”>i = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0<span style=“font-size: 9pt; font-family: “Courier New”;”>; i <
attachments.size(); i++) {
MapiAttachment attachment =
(MapiAttachment) attachments.get_Item(i);
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(IsInlineAttachment(attachment,
message.getBodyType())) {
System.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out<span style=“font-size: 9pt; font-family: “Courier New”;”>.println(attachment.getLongFileName()
-
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:green”>" is inline attachment"<span style=“font-size: 9pt; font-family: “Courier New”;”>);
} <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else <span style=“font-size: 9pt; font-family: “Courier New”;”>{
System.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out<span style=“font-size: 9pt; font-family: “Courier New”;”>.println(attachment.getLongFileName() -
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:green”>" is regular attachment"<span style=“font-size: 9pt; font-family: “Courier New”;”>);
}
}
}
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:navy”>public static boolean <span style=“font-size: 9pt; font-family: “Courier New”;”>IsInlineAttachment(MapiAttachment att, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>int <span style=“font-size: 9pt; font-family: “Courier New”;”>messageBodyType)
{
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(messageBodyType ==
BodyContentType.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>PlainText<span style=“font-size: 9pt; font-family: “Courier New”;”>)
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// ignore indications for plain text messages
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return false<span style=“font-size: 9pt; font-family: “Courier New”;”>;
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if <span style=“font-size: 9pt; font-family: “Courier New”;”>(messageBodyType ==
BodyContentType.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Html<span style=“font-size: 9pt; font-family: “Courier New”;”>)
{
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// check the PidTagAttachFlags property
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x37140003<span style=“font-size: 9pt; font-family: “Courier New”;”>))
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>long <span style=“font-size: 9pt; font-family: “Courier New”;”>attachFlagsValue =
att.getPropertyLong(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0x37140003<span style=“font-size: 9pt; font-family: “Courier New”;”>);
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>((attachFlagsValue &
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:blue”>0x00000004<span style=“font-size: 9pt; font-family: “Courier New”;”>)
== <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:blue”>0x00000004<span style=“font-size: 9pt; font-family: “Courier New”;”>)
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// check PidTagAttachContentId property
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID<span style=“font-size: 9pt; font-family: “Courier New”;”>)
||
att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID_W<span style=“font-size: 9pt; font-family: “Courier New”;”>))
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// check PidTagAttachContentId property
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID<span style=“font-size: 9pt; font-family: “Courier New”;”>)
||
att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID_W<span style=“font-size: 9pt; font-family: “Courier New”;”>))
{
<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:navy”>return
true<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// check PidTagAttachContentLocation property
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3713001E<span style=“font-size: 9pt; font-family: “Courier New”;”>) ||
att.getProperties().containsKey(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>0x3713001F<span style=“font-size: 9pt; font-family: “Courier New”;”>))
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
}
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if<span style=“font-size: 9pt; font-family: “Courier New”;”>((att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>) &&
att.getPropertyString(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“inline”<span style=“font-size: 9pt; font-family: “Courier New”;”>))
||
(att.getProperties().containsKey(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>) && att.getPropertyString(<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“inline”<span style=“font-size: 9pt; font-family: “Courier New”;”>)))
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
}
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if<span style=“font-size: 9pt; font-family: “Courier New”;”>((att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>) &&
att.getPropertyString(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“inline”<span style=“font-size: 9pt; font-family: “Courier New”;”>))
||
(att.getProperties().containsKey(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>) && att.getPropertyString(<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“inline”<span style=“font-size: 9pt; font-family: “Courier New”;”>)))
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return false<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if <span style=“font-size: 9pt; font-family: “Courier New”;”>(messageBodyType ==
BodyContentType.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Rtf<span style=“font-size: 9pt; font-family: “Courier New”;”>)
{
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// If the body is RTF, then all OLE attachments are inline
attachments.
// OLE attachments have
0x00000006 for the value of the PidTagAttachMethod property
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_METHOD<span style=“font-size: 9pt; font-family: “Courier New”;”>))
{
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return <span style=“font-size: 9pt; font-family: “Courier New”;”>att.getPropertyLong(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_METHOD<span style=“font-size: 9pt; font-family: “Courier New”;”>)
== <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:blue”>0x00000006<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return false<span style=“font-size: 9pt; font-family: “Courier New”;”>;
}
<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else
throw new <span style=“font-size: 9pt; font-family: “Courier New”;”>ArgumentOutOfRangeException();
}
Thanks Kashif.
Hi Rajiv,
Thanks !
You are welcome.