View Single Post
  #5  
Old July 7th 09, 03:47 AM posted to microsoft.public.outlook.program_vba
anindasen_0609[_2_]
external usenet poster
 
Posts: 15
Default Plugin registering the same email twice.

"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



Ads