My Profile
Gifts
Active Members
TodayLast 7 Days
more...
|
Extract Message and Attachment From lotus Notes
Posted Date: 13 May 2008 Resource Type: Articles Category: General
|
Posted By: Raamkumar Member Level: Silver Rating: Points: 50
|
Install Lotus Notes in your system and refer "Lotus Domino Objects"
using Domino;
//General Declaration
StreamReader reader; int Mailcnt = 0; string AttachmentName; StringBuilder sp = new StringBuilder();
/// Add Button and Copy and Paste the Code
private void button1_Click(object sender, EventArgs e) { int numberDocs = 0; try { NotesSession notesSession = new NotesSessionClass(); notesSession.Initialize(string.Empty); NotesDatabase notesDB; notesDB = notesSession.GetDatabase("",@"D:\Sample.nsf", false); if (!notesDB.IsOpen) { notesDB.Open(); } NotesView vW = null; NotesDocument nDoc; if (notesDB != null) vW = notesDB.GetView("($Sent)"); nDoc = vW.GetFirstDocument(); while (nDoc != null) { numberDocs++; object[] objects = (object[])nDoc.Items; StringBuilder sp = new StringBuilder(); Hashtable Properties = new Hashtable(); sp = FileStringBuilder(sp); foreach (object ob in objects) { NotesItem notesItem = (NotesItem)ob;
if (notesItem.Name != null) if (!Properties.Contains(notesItem.Name)) Properties.Add(notesItem.Name, notesItem.Text);
if (notesItem.Name == "$FILE") { object[] values = (object[])notesItem.Values; AttachmentName = ""; foreach (object o in values) { SaveAttachment(nDoc, o.ToString());
if (AttachmentName != "") AttachmentName = "," + o.ToString(); else AttachmentName = o.ToString(); } } } WriteHtmlfile(sp, Properties); Properties.Clear(); nDoc = vW.GetNextDocument(nDoc); } } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show(Convert.ToString(numberDocs)); }
//////////Add this Three Method//////////////// private static void SaveAttachment(NotesDocument nDoc, string fileName) { NotesEmbeddedObject attachment = nDoc.GetAttachment(fileName); if (attachment != null) { Console.WriteLine("Saving new attachment to file " + fileName); attachment.ExtractFile("D:\\SampleOutput\\LotusNotes\\ " + fileName); } } private StringBuilder FileStringBuilder(StringBuilder sb) { StreamReader reader = new StreamReader(@"C:\Documents and Settings\5563\Desktop\NFSTemplate\Template.htm"); sb.Append(reader.ReadToEnd()); reader.Close(); return sb; } private void WriteHtmlfile(StringBuilder sp, Hashtable tble) { if (tble["From"]!= null) { sp.Replace("#From#", tble["From"].ToString()); }
if (tble["PostedDate"] != null) { sp.Replace("#Sent#", tble["PostedDate"].ToString()); }
if (tble["SendTo"] != null) { sp.Replace("#To#", tble["SendTo"].ToString()); } if (tble["Subject"] != null) { sp.Replace("#Subject#", tble["Subject"].ToString()); } ////To make new lines in the template file. if (tble["Body"]!= null) { string body = tble["Body"].ToString(); string ToBody = body.Replace("\r\n", "<br>"); sp.Replace("#Body#", ToBody); } //sp.Replace("#Attach#", AttachmentName); StreamWriter writer = new StreamWriter(@"D:\\SampleOutput\\LotusNotes\\Mail00" + Mailcnt + ".htm"); writer.Write(sp.ToString()); writer.Close(); Mailcnt += 1; }
////Before You Shoud Create Template for Saving mail format.
copy and paste in notepad and saveas (Template.htm) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- Presaved CDS EDD Email --><HTML xmlns:o = "urn:schemas-microsoft-com:office:office" xmlns:w = "urn:schemas-microsoft-com:office:word"><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content=Word.Document name=ProgId> <META content="MSHTML 6.00.2900.3059" name=GENERATOR> <META content="Microsoft Word 11" name=Originator><LINK href="cid:filelist.xml@01C71EEA.62D03020" rel=File-List><!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:DoNotRelyOnCSS/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:SpellingState>Clean</w:SpellingState> <w:GrammarState>Clean</w:GrammarState> <w:DocumentKind>DocumentEmail</w:DocumentKind> <w:EnvelopeVis/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <STYLE>@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; mso-header-margin: .5in; mso-footer-margin: .5in; mso-paper-source: 0; } P.MsoNormal { FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman" } LI.MsoNormal { FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman" } DIV.MsoNormal { FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman" } A:link { COLOR: blue; TEXT-DECORATION: underline; text-underline: single } SPAN.MsoHyperlink { COLOR: blue; TEXT-DECORATION: underline; text-underline: single } A:visited { COLOR: purple; TEXT-DECORATION: underline; text-underline: single } SPAN.MsoHyperlinkFollowed { COLOR: purple; TEXT-DECORATION: underline; text-underline: single } SPAN.EmailStyle17 { COLOR: windowtext; FONT-FAMILY: Arial; mso-style-type: personal-compose; mso-style-noshow: yes; mso-ansi-font-size: 10.0pt; mso-bidi-font-size: 10.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial } DIV.Section1 { page: Section1 } </STYLE> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--></HEAD> <BODY lang=EN-US style="tab-interval: .5in" vLink=purple link=blue> <TABLE width="95%" border=0> <TBODY> <TR> <TD vAlign=top width=100><STRONG>From: </STRONG> </TD> <TD>#From#</TD></TR> <TR> <TD width=100><STRONG>Sent: </STRONG> </TD> <TD>#Sent#</TD></TR> <TR> <TD vAlign=top width=100><STRONG>To: </STRONG> </TD> <TD>#To#</TD></TR> <TR> <TD vAlign=top width=100><STRONG>Subject: </STRONG> </TD> <TD>#Subject#</TD></TR> <TR> <TD vAlign=top width=100><STRONG>Attach: </STRONG> </TD> <TD>#Attach#</TD></TR></TBODY></TABLE> <HR color=#000000 noShade SIZE=2>
<DIV class=Section1> <P class=MsoNormal><FONT face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p>#Body#</o:p></SPAN></FONT></P></DIV></BODY></HTML>
|
Responses
|
| Author: Deepa 17 Jun 2008 | Member Level: Diamond Points : 0 | Very long........
|
|