![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
I have created a plugin and it is working ok but something strange is happening. Incoming emails which have two attachments are getting recorded twice in the database as the same email. This is the same outlook plugin for which I created a thread on 6/5/2009 under the heading "Help with some issues in Outlook Plugin development." Can anybody help me out on this? I am basically taking the attachments and uploading it to the server with (edtftpNet - free command line ftp) after saving the email details to the server database through webservice. Regards, Aninda |
Ads |
#2
|
|||
|
|||
![]()
There's no way to tell from what you posted what the problem is. You need to
post the relevant section of your code for people here to look at. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "anindasen_0609" wrote in message ... Hi, I have created a plugin and it is working ok but something strange is happening. Incoming emails which have two attachments are getting recorded twice in the database as the same email. This is the same outlook plugin for which I created a thread on 6/5/2009 under the heading "Help with some issues in Outlook Plugin development." Can anybody help me out on this? I am basically taking the attachments and uploading it to the server with (edtftpNet - free command line ftp) after saving the email details to the server database through webservice. Regards, Aninda |
#3
|
|||
|
|||
![]()
Here it is:
private void m_Items_ItemAdd(object addedItem) { Outlook.MailItem newItem = (Outlook.MailItem)addedItem; toEmailID = userEmailID; string fromEmailID = ""; string toAddress = null; string ccAddress = null; string bccAddress = null; if (newItem.To != null) toAddress = ""; if (newItem.CC != null) ccAddress = ""; if (newItem.BCC != null) bccAddress = ""; Outlook.Recipients recpts = newItem.Recipients; if (recpts != null) { for (int ii = 1; ii (recpts.Count + 1); ii++) { //Dim recipient As Outlook.Recipient = recipients.Item(i) Outlook.Recipient recpt = recpts[ii]; { if (recpt != null) { if (recpt.Type == 1) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { toAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { toAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } else if (recpt.Type == 2) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { ccAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { ccAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } else if (recpt.Type == 3) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { bccAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { bccAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } } } } } if (newItem.To != null) toAddress = toAddress.Substring(0, toAddress.Length - 1); if (newItem.CC != null) ccAddress = ccAddress.Substring(0, ccAddress.Length - 1); if (newItem.BCC != null) bccAddress = bccAddress.Substring(0, bccAddress.Length - 1); if (newItem.SenderEmailType == "EX") fromEmailID = (string)newItem.PropertyAccessor.GetProperty(Schem aSMTPAddress); else fromEmailID = newItem.SenderEmailAddress; //If fromEmailID is not in Email format get it from GAL (Global Address List) if (fromEmailID.IndexOf("@") = 0) { fromEmailID = GetEmailID(ref fromEmailID); } int fromContactID = 0; fromContactID = (int)GetContactID(fromEmailID); //Communication Type: 0 - Incoming 1 - Outgoing string GUIDFolderName = Guid.NewGuid().ToString(); int newCommunicationID = 0; ArrayList emailList = new ArrayList(); try { CMSService cmsServ = new CMSService(); newCommunicationID = cmsServ.InsertCommunication(fromContactID, fromEmailID, toAddress, ccAddress, bccAddress, newItem.Subject, newItem.HTMLBody, Convert.ToInt32(userID), DateTime.Now, 0, newItem.Body, GUIDFolderName); //Save attachments if any if (newItem.Attachments.Count 0) { ftpConnect(); ftp.ChDir("OutlookAttachments"); ftp.MkDir(GUIDFolderName); ftp.ChDir(GUIDFolderName); for (int i = 1; i = newItem.Attachments.Count; i++) { newItem.Attachments[i].SaveAsFile(sourcePath + @"\" + newItem.Attachments[i].FileName); ftp.Put(sourcePath + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); File.Delete(sourcePath + @"\" + newItem.Attachments[i].FileName); cmsServ.InsertCommunicationAttachment(GUIDFolderNa me, newCommunicationID, GUIDFolderName + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); } ftp.Quit(); } } catch (Exception ex) { string errorInfo = (string)ex.Message.Substring(0, 11); } } Regards, Aninda "Ken Slovak - [MVP - Outlook]" wrote: There's no way to tell from what you posted what the problem is. You need to post the relevant section of your code for people here to look at. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "anindasen_0609" wrote in message ... Hi, I have created a plugin and it is working ok but something strange is happening. Incoming emails which have two attachments are getting recorded twice in the database as the same email. This is the same outlook plugin for which I created a thread on 6/5/2009 under the heading "Help with some issues in Outlook Plugin development." Can anybody help me out on this? I am basically taking the attachments and uploading it to the server with (edtftpNet - free command line ftp) after saving the email details to the server database through webservice. Regards, Aninda |
#4
|
|||
|
|||
![]()
I can't tell from that mess of code where you're recording the email in the
database, but if it's in the line that starts with cmsServ.InsertCommunicationAttachment then that's inside the for loop and will cause the same item to be inserted once for each attachment in the email. You really should not be using multiple dot operators with the COM properties of Outlook items. It ends up creating invisible object variables you can't delete or remove. Something like: recpt.PropertyAccessor.GetProperty(SchemaAddressTy pe).ToString() == "EX" can end up causing you lots of problems, especially if Exchange is involved. You should get the PropertyAccessor object, then call the GetProperty() method on that object instead of letting an invisible PropertyAccessor object be created. The same applies everywhere you are using multiple dot operators. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "anindasen_0609" wrote in message ...[i] Here it is: private void m_Items_ItemAdd(object addedItem) { Outlook.MailItem newItem = (Outlook.MailItem)addedItem; toEmailID = userEmailID; string fromEmailID = ""; string toAddress = null; string ccAddress = null; string bccAddress = null; if (newItem.To != null) toAddress = ""; if (newItem.CC != null) ccAddress = ""; if (newItem.BCC != null) bccAddress = ""; Outlook.Recipients recpts = newItem.Recipients; if (recpts != null) { for (int ii = 1; ii (recpts.Count + 1); ii++) { //Dim recipient As Outlook.Recipient = recipients.Item(i) Outlook.Recipient recpt = recpts[ii]; { if (recpt != null) { if (recpt.Type == 1) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { toAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { toAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } else if (recpt.Type == 2) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { ccAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { ccAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } else if (recpt.Type == 3) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { bccAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { bccAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } } } } } if (newItem.To != null) toAddress = toAddress.Substring(0, toAddress.Length - 1); if (newItem.CC != null) ccAddress = ccAddress.Substring(0, ccAddress.Length - 1); if (newItem.BCC != null) bccAddress = bccAddress.Substring(0, bccAddress.Length - 1); if (newItem.SenderEmailType == "EX") fromEmailID = (string)newItem.PropertyAccessor.GetProperty(Schem aSMTPAddress); else fromEmailID = newItem.SenderEmailAddress; //If fromEmailID is not in Email format get it from GAL (Global Address List) if (fromEmailID.IndexOf("@") = 0) { fromEmailID = GetEmailID(ref fromEmailID); } int fromContactID = 0; fromContactID = (int)GetContactID(fromEmailID); //Communication Type: 0 - Incoming 1 - Outgoing string GUIDFolderName = Guid.NewGuid().ToString(); int newCommunicationID = 0; ArrayList emailList = new ArrayList(); try { CMSService cmsServ = new CMSService(); newCommunicationID = cmsServ.InsertCommunication(fromContactID, fromEmailID, toAddress, ccAddress, bccAddress, newItem.Subject, newItem.HTMLBody, Convert.ToInt32(userID), DateTime.Now, 0, newItem.Body, GUIDFolderName); //Save attachments if any if (newItem.Attachments.Count 0) { ftpConnect(); ftp.ChDir("OutlookAttachments"); ftp.MkDir(GUIDFolderName); ftp.ChDir(GUIDFolderName); for (int i = 1; i = newItem.Attachments.Count; i++) { newItem.Attachments[i].SaveAsFile(sourcePath + @"\" + newItem.Attachments[i].FileName); ftp.Put(sourcePath + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); File.Delete(sourcePath + @"\" + newItem.Attachments[i].FileName); cmsServ.InsertCommunicationAttachment(GUIDFolderNa me, newCommunicationID, GUIDFolderName + @"\" + newItem.Attachments[i].FileName, newItem.Attachments.FileName); } ftp.Quit(); } } catch (Exception ex) { string errorInfo = (string)ex.Message.Substring(0, 11); } } Regards, Aninda |
#5
|
|||
|
|||
![]()
"I can't tell from that mess of code where you're recording the email in the
database" -- If it is a mess can you tell me what makes you feel so and some suggestions for improvement? "but if it's in the line that starts with cmsServ.InsertCommunicationAttachment then that's inside the for loop and will cause the same item to be inserted once for each attachment in the email." -- As you can see if you observe a little closely that saving into the database is not inside the for loop. The one that is getting saved inside the loop is to the attachment details table as below: try { CMSService cmsServ = new CMSService(); newCommunicationID = cmsServ.InsertCommunication(fromContactID, fromEmailID, toAddress, ccAddress, bccAddress, newItem.Subject, newItem.HTMLBody, Convert.ToInt32(userID), DateTime.Now, 0, newItem.Body, GUIDFolderName); //Save attachments if any if (newItem.Attachments.Count 0) { ftpConnect(); ftp.ChDir("OutlookAttachments"); ftp.MkDir(GUIDFolderName); ftp.ChDir(GUIDFolderName); for (int i = 1; i = newItem.Attachments.Count; i++) { newItem.Attachments[i].SaveAsFile(sourcePath + @"\" + newItem.Attachments[i].FileName); ftp.Put(sourcePath + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); File.Delete(sourcePath + @"\" + newItem.Attachments[i].FileName); cmsServ.InsertCommunicationAttachment(GUIDFolderNa me, newCommunicationID, GUIDFolderName + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); } ftp.Quit(); } } catch (Exception ex) { string errorInfo = (string)ex.Message.Substring(0, 11); } } Your comment regarding dot operator has been noted. Thanks. Regards, Aninda "Ken Slovak - [MVP - Outlook]" wrote: [i] I can't tell from that mess of code where you're recording the email in the database, but if it's in the line that starts with cmsServ.InsertCommunicationAttachment then that's inside the for loop and will cause the same item to be inserted once for each attachment in the email. You really should not be using multiple dot operators with the COM properties of Outlook items. It ends up creating invisible object variables you can't delete or remove. Something like: recpt.PropertyAccessor.GetProperty(SchemaAddressTy pe).ToString() == "EX" can end up causing you lots of problems, especially if Exchange is involved. You should get the PropertyAccessor object, then call the GetProperty() method on that object instead of letting an invisible PropertyAccessor object be created. The same applies everywhere you are using multiple dot operators. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "anindasen_0609" wrote in message ...[i] Here it is: private void m_Items_ItemAdd(object addedItem) { Outlook.MailItem newItem = (Outlook.MailItem)addedItem; toEmailID = userEmailID; string fromEmailID = ""; string toAddress = null; string ccAddress = null; string bccAddress = null; if (newItem.To != null) toAddress = ""; if (newItem.CC != null) ccAddress = ""; if (newItem.BCC != null) bccAddress = ""; Outlook.Recipients recpts = newItem.Recipients; if (recpts != null) { for (int ii = 1; ii (recpts.Count + 1); ii++) { //Dim recipient As Outlook.Recipient = recipients.Item(i) Outlook.Recipient recpt = recpts[ii]; { if (recpt != null) { if (recpt.Type == 1) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { toAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { toAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } else if (recpt.Type == 2) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { ccAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { ccAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } else if (recpt.Type == 3) { if (recpt.PropertyAccessor.GetProperty(SchemaAddressT ype).ToString() == "EX") { bccAddress += recpt.PropertyAccessor.GetProperty(SchemaSMTPAddre ss).ToString().Replace("'", "") + ";"; } else { bccAddress += recpt.Address.ToString().Replace("'", "") + ";"; } } } } } } if (newItem.To != null) toAddress = toAddress.Substring(0, toAddress.Length - 1); if (newItem.CC != null) ccAddress = ccAddress.Substring(0, ccAddress.Length - 1); if (newItem.BCC != null) bccAddress = bccAddress.Substring(0, bccAddress.Length - 1); if (newItem.SenderEmailType == "EX") fromEmailID = (string)newItem.PropertyAccessor.GetProperty(Schem aSMTPAddress); else fromEmailID = newItem.SenderEmailAddress; //If fromEmailID is not in Email format get it from GAL (Global Address List) if (fromEmailID.IndexOf("@") = 0) { fromEmailID = GetEmailID(ref fromEmailID); } int fromContactID = 0; fromContactID = (int)GetContactID(fromEmailID); //Communication Type: 0 - Incoming 1 - Outgoing string GUIDFolderName = Guid.NewGuid().ToString(); int newCommunicationID = 0; ArrayList emailList = new ArrayList(); try { CMSService cmsServ = new CMSService(); newCommunicationID = cmsServ.InsertCommunication(fromContactID, fromEmailID, toAddress, ccAddress, bccAddress, newItem.Subject, newItem.HTMLBody, Convert.ToInt32(userID), DateTime.Now, 0, newItem.Body, GUIDFolderName); //Save attachments if any if (newItem.Attachments.Count 0) { ftpConnect(); ftp.ChDir("OutlookAttachments"); ftp.MkDir(GUIDFolderName); ftp.ChDir(GUIDFolderName); for (int i = 1; i = newItem.Attachments.Count; i++) { newItem.Attachments[i].SaveAsFile(sourcePath + @"\" + newItem.Attachments[i].FileName); ftp.Put(sourcePath + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); File.Delete(sourcePath + @"\" + newItem.Attachments[i].FileName); cmsServ.InsertCommunicationAttachment(GUIDFolderNa me, newCommunicationID, GUIDFolderName + @"\" + newItem.Attachments.FileName, newItem.Attachments.FileName); } ftp.Quit(); } } catch (Exception ex) { string errorInfo = (string)ex.Message.Substring(0, 11); } } Regards, Aninda |
#6
|
|||
|
|||
![]()
I apologize if you thought I meant your code was messy, I was use "mess of
code" with the meaning of a "whole lot of code to look at". I'd recommend stepping the code and seeing exactly where and when that second entry in the database is being made. Are the attachment details table entries also duplicated? In that case it might be worth seeing if your procedure is being called more than once per item, more often than you expect. You can put a Debug.WriteLine() line in that event handler that notes that the event has fired to help you keep track of that. If that's the case then you can use a flag to indicate that you've already handled the event for that item. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "anindasen_0609" wrote in message ...[i] "I can't tell from that mess of code where you're recording the email in the database" -- If it is a mess can you tell me what makes you feel so and some suggestions for improvement? "but if it's in the line that starts with cmsServ.InsertCommunicationAttachment then that's inside the for loop and will cause the same item to be inserted once for each attachment in the email." -- As you can see if you observe a little closely that saving into the database is not inside the for loop. The one that is getting saved inside the loop is to the attachment details table as below: try { CMSService cmsServ = new CMSService(); newCommunicationID = cmsServ.InsertCommunication(fromContactID, fromEmailID, toAddress, ccAddress, bccAddress, newItem.Subject, newItem.HTMLBody, Convert.ToInt32(userID), DateTime.Now, 0, newItem.Body, GUIDFolderName); //Save attachments if any if (newItem.Attachments.Count 0) { ftpConnect(); ftp.ChDir("OutlookAttachments"); ftp.MkDir(GUIDFolderName); ftp.ChDir(GUIDFolderName); for (int i = 1; i = newItem.Attachments.Count; i++) { newItem.Attachments[i].SaveAsFile(sourcePath + @"\" + newItem.Attachments[i].FileName); ftp.Put(sourcePath + @"\" + newItem.Attachments[i].FileName, newItem.Attachments[i].FileName); File.Delete(sourcePath + @"\" + newItem.Attachments[i].FileName); cmsServ.InsertCommunicationAttachment(GUIDFolderNa me, newCommunicationID, GUIDFolderName + @"\" + newItem.Attachments[i].FileName, newItem.Attachments.FileName); } ftp.Quit(); } } catch (Exception ex) { string errorInfo = (string)ex.Message.Substring(0, 11); } } Your comment regarding dot operator has been noted. Thanks. Regards, Aninda |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
redemption dll not registering in windows vista | wlan | Outlook - Using Forms | 3 | May 29th 09 01:29 AM |
registering Outlook 2002 to a new computer | Atomic2Mod | Outlook - Installation | 1 | August 30th 08 10:10 PM |
Registering events on calendar items on startup | Manish | Add-ins for Outlook | 4 | May 12th 08 08:31 PM |
Outlook plugin and acrobat reader email option | [email protected] | Add-ins for Outlook | 1 | June 9th 06 12:28 AM |
path syntax while registering msoe.dll | Tom Penharston | Outlook Express | 3 | January 22nd 06 05:09 PM |