UserProperty of mail object problem while dealing with custom fold

  • Thread starter Problem with UserProperty of mail object
  • Start date
Status
Not open for further replies.
P

Problem with UserProperty of mail object

hi,

The error i come across while dealing with saving the

UserProperties of mails being directed to custom folders is 'The operation

cannot be performed because the message has been changed.'

The following is my code.

// this is called in 'ThisAddIn_Startup' method whenver a new mail is received

this.Application.NewMailEx += new

Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);

// the definition for 'Application_NewMailEx' is as follows

void Application_NewMailEx(string EntryIDCollection) //autolinking

{

if (strAutoLink == "ON")

{

string[] entries = EntryIDCollection.Split(',');

for (int c = 0; c < entries.Length; c++)

{

objMailItems =

(Outlook.MailItem)objNamesSpace.GetItemFromID(entries.GetValue(c).ToString(),

objInbox.StoreID);

threadMail = new Thread(new ThreadStart(fnNewMailRecv));

threadMail.Start();

}

}

}

//the definition for 'fnNewMailRecv()' is as follows

public void fnNewMailRecv()

{

try

{

Outlook.MailItem newMail = objMailItems;

currentMail = objMailItems;

GenModClass objGenMod = new GenModClass();

bool toLink = ThisAddIn.bLinkInCRM;

string strSenderName = newMail.SenderName.ToString();

string strUserName = objUser.userName.ToUpper();

Outlook.NameSpace objOUTLOOKNS =

this.Application.GetNamespace("MAPI");

Outlook.UserProperty objCRMGoldRecid;

Outlook.UserProperty objLinkedToContact;

Outlook.UserProperty objLinkedToCompany;

Outlook.UserProperty objLinkCheckBox;

newMail.Save();

objCRMGoldRecid = newMail.UserProperties.Add("RECID",

Outlook.OlUserPropertyType.olText, true, System.Reflection.Missing.Value);

objLinkedToContact = newMail.UserProperties.Add("Linked

to Contact", Outlook.OlUserPropertyType.olText, true,

System.Reflection.Missing.Value);

objLinkedToCompany = newMail.UserProperties.Add("Linked

to Company", Outlook.OlUserPropertyType.olText, true,

System.Reflection.Missing.Value);

objLinkCheckBox = newMail.UserProperties.Add("Is

Linked", Outlook.OlUserPropertyType.olYesNo, true,

System.Reflection.Missing.Value);

string strSenderEmailAddress = "";

if (newMail.SenderEmailAddress != null)

{

strSenderEmailAddress =

newMail.SenderEmailAddress.ToString();

string strFrom = strSenderEmailAddress == null ? ""

: strSenderEmailAddress;

string strTo = newMail.To == null ? "" : newMail.To;

string strCC = newMail.CC == null ? "" : newMail.CC;

string strBcc = newMail.BCC == null ? "" :

newMail.BCC;

string strSubject = newMail.Subject == null ? "" :

newMail.Subject;

if (strSubject.Length > 80)

strSubject = strSubject.Substring(0,

80).ToString();

string strMsgBody = newMail.HTMLBody == null ? "" :

newMail.HTMLBody;

string strImp = newMail.Importance.ToString();

string strAccountNo=string.Empty;

//gnerating some id

string strMailBoxRecID =

objGenMod.GenerateRecId().ToString(); string

strHasAttachment = (newMail.Attachments.Count > 0) ? "Yes" : "No";

//to get a user's account no from my database

string sqlQuery = "SELECT

dbo.Fun_Email_getLinkAccountNo('" + strSenderEmailAddress + "') AS

ACCOUNTNO";

DataSet ds= new DataSet();

try

{

// calling the webservice

ds =

crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,

objUser.userName, ThisAddIn.IPAddress);

}

catch (Exception Ex)

{

MessageBox.Show(Ex.Message);

fnWriteErrorLog(Ex);

return;

}

if (ds.Tables.Count > 0)

{

if (ds.Tables[0].Rows.Count > 0)

{

strAccountNo =

ds.Tables[0].Rows[0]["ACCOUNTNO"].ToString();

}

else

strAccountNo = "";

}

if (strAccountNo == "") //email address not found

in db

{

objCRMGoldRecid.Value = "UNLINKED";

objLinkedToContact.Value = "";

objLinkedToCompany.Value = "";

objLinkCheckBox.Value = false;

}

if (strAccountNo != "")

{

StringBuilder strRFC822 = new StringBuilder();

strRFC822.Append(" ");

string strMessageID = newMail.EntryID;

strRFC822.Append(newMail.ReceivedTime.ToString("ddd, dd MMM yyyy

hh:mm:ss")); //0

strRFC822.Append("^ ");

strRFC822.Append(strFrom); //1

strRFC822.Append("^ ");

strRFC822.Append(strSubject); //2

strRFC822.Append("^ ");

strRFC822.Append(strTo); //3

strRFC822.Append("^ ");

strRFC822.Append(strCC);//4

strRFC822.Append("^ ");

strRFC822.Append(strHasAttachment);//5

strRFC822.Append("^ <");

strRFC822.Append(strMessageID);//6

strRFC822.Append(">");

strRFC822.Append("^ ");

strRFC822.Append(strMsgBody);//7

strRFC822.Append("^ ");

string oldFileName = string.Empty;

string extn = string.Empty;

string FileName = string.Empty;

string emailattachments = "";

strRFC822.Append(emailattachments);//8

strRFC822.Append("^ ");

strRFC822.Append(newMail.BodyFormat.ToString());//9

if (strSubject.Length > 80)

strSubject = strSubject.Substring(0, 80);

string strRecdOnDate =

newMail.ReceivedTime.ToString();

sqlQuery = "SELECT companyid FROM

tblcompanycontact WHERE accountno='" + strAccountNo + "'";

try

{

//calling webservice

ds =

crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,

objUser.userName.ToUpper(), ThisAddIn.IPAddress);

}

catch (Exception Ex)

{

MessageBox.Show(Ex.Message);

fnWriteErrorLog(Ex);

return;

}

//create new database record

crmEZService.EmailMessage objEmailMessage =

new CRMGoldOutlook.crmEZService.EmailMessage();

objEmailMessage.recID = "";

objEmailMessage.Flags = "";

objEmailMessage.lopRecId = "";

objEmailMessage.Folder = strFolderType;

objEmailMessage.Folder2 = "";

objEmailMessage.MessageID = strMessageID;

objEmailMessage.Attachment = strHasAttachment;

objEmailMessage.userId =

objUser.userName.ToUpper();

objEmailMessage.MailSize =

newMail.Size.ToString();

objEmailMessage.MailDate =

DateTime.Parse(strRecdOnDate).ToString("yyyy-MM-dd");

objEmailMessage.MailTime =

newMail.ReceivedTime.ToString("HH:mm");

objEmailMessage.MailRef = strSubject;

objEmailMessage.RFC822 = strRFC822.ToString();

objEmailMessage.contactID = strAccountNo;

objEmailMessage.linkRecId = "";

string MAILBOXRECID = string.Empty;

try

{

//a new id is generated and returned by webservice

MAILBOXRECID =

crmService.createNewCRMObject(ThisAddIn.SessionID, objEmailMessage,

ThisAddIn.objUser.userName.ToUpper(), ThisAddIn.IPAddress);

}

catch (Exception Ex)

{

MessageBox.Show(Ex.Message);

fnWriteErrorLog(Ex);

return;

}

sqlQuery = "SELECT ISNULL(company,'')as

Company, ISNULL(contact,'') as Contact FROM contact1 WHERE accountno='" +

strAccountNo + "'";

try

{

ds =

crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,

objUser.userName.ToUpper(), ThisAddIn.IPAddress);

}

catch (Exception Ex)

{

MessageBox.Show(Ex.Message);

fnWriteErrorLog(Ex);

return;

}

// From here onwards, if there are no 'Rules and Alerts' specifed to direct

the received mails to custom folder, the values are assigned

// perfectly to UserProperties. But when

there are rules mentioned to move the received mail to a user created

'Personal folder', then

// the following error is thrown 'The operation cannot be performed

because the message has been changed.' and the values are not fed

// into the user properties.

if (ds.Tables.Count > 0)

{

if (ds.Tables[0].Rows.Count > 0)

{

if (objCRMGoldRecid != null)

{

objCRMGoldRecid.Value =

MAILBOXRECID;

}

objLinkedToContact.Value =

ds.Tables[0].Rows[0]["Contact"].ToString();

objLinkedToCompany.Value =

ds.Tables[0].Rows[0]["Company"].ToString();

objLinkCheckBox.Value = true;

}

}

newMail.Save();

}

}

}

catch (Exception Ex)

{

MessageBox.Show(Ex.Message);

fnWriteErrorLog(Ex);

}

}

Thanks in advance.
 
K

Ken Slovak - [MVP - Outlook]

You're using a new thread to access the Outlook object model, which is

really, really bad. That is not supported and will cause Outlook to crash or

hang in most cases. Get rid of that and localize where the problem is coming

in your code. You need to show only the relevant code, no one is going to

want to wade through all that code to try to find problems.

"Problem with UserProperty of mail object"

<ProblemwithUserPropertyofmailobject> wrote in

message news:1228956D-3C18-430B-BA46-1C9B0BF496BB@microsoft.com...
> hi,
> The error i come across while dealing with saving the
> UserProperties of mails being directed to custom folders is 'The operation
> cannot be performed because the message has been changed.'

> The following is my code.

> // this is called in 'ThisAddIn_Startup' method whenver a new mail is
> received
> this.Application.NewMailEx += new
> Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);

> // the definition for 'Application_NewMailEx' is as follows
> void Application_NewMailEx(string EntryIDCollection) //autolinking
> {
> if (strAutoLink == "ON")
> {
> string[] entries = EntryIDCollection.Split(',');
> for (int c = 0; c < entries.Length; c++)
> {
> objMailItems =
> (Outlook.MailItem)objNamesSpace.GetItemFromID(entries.GetValue(c).ToString(),
> objInbox.StoreID);
> threadMail = new Thread(new ThreadStart(fnNewMailRecv));

> threadMail.Start();
> }
> }
> }

> //the definition for 'fnNewMailRecv()' is as follows
> public void fnNewMailRecv()
> {
> try
> {
> Outlook.MailItem newMail = objMailItems;
> currentMail = objMailItems;
> GenModClass objGenMod = new GenModClass();
> bool toLink = ThisAddIn.bLinkInCRM;
> string strSenderName = newMail.SenderName.ToString();
> string strUserName = objUser.userName.ToUpper();

> Outlook.NameSpace objOUTLOOKNS =
> this.Application.GetNamespace("MAPI");

> Outlook.UserProperty objCRMGoldRecid;
> Outlook.UserProperty objLinkedToContact;
> Outlook.UserProperty objLinkedToCompany;
> Outlook.UserProperty objLinkCheckBox;

> newMail.Save();

> objCRMGoldRecid = newMail.UserProperties.Add("RECID",
> Outlook.OlUserPropertyType.olText, true, System.Reflection.Missing.Value);
> objLinkedToContact = newMail.UserProperties.Add("Linked
> to Contact", Outlook.OlUserPropertyType.olText, true,
> System.Reflection.Missing.Value);
> objLinkedToCompany = newMail.UserProperties.Add("Linked
> to Company", Outlook.OlUserPropertyType.olText, true,
> System.Reflection.Missing.Value);
> objLinkCheckBox = newMail.UserProperties.Add("Is
> Linked", Outlook.OlUserPropertyType.olYesNo, true,
> System.Reflection.Missing.Value);

> string strSenderEmailAddress = "";
> if (newMail.SenderEmailAddress != null)
> {
> strSenderEmailAddress =
> newMail.SenderEmailAddress.ToString();

> string strFrom = strSenderEmailAddress == null ? ""
> : strSenderEmailAddress;
> string strTo = newMail.To == null ? "" :
> newMail.To;
> string strCC = newMail.CC == null ? "" :
> newMail.CC;
> string strBcc = newMail.BCC == null ? "" :
> newMail.BCC;
> string strSubject = newMail.Subject == null ? "" :
> newMail.Subject;
> if (strSubject.Length > 80)
> strSubject = strSubject.Substring(0,
> 80).ToString();
> string strMsgBody = newMail.HTMLBody == null ? "" :
> newMail.HTMLBody;

> string strImp = newMail.Importance.ToString();

> string strAccountNo=string.Empty;

> //gnerating some id
> string strMailBoxRecID =
> objGenMod.GenerateRecId().ToString(); string
> strHasAttachment = (newMail.Attachments.Count > 0) ? "Yes" : "No";

> //to get a user's account no from my database
> string sqlQuery = "SELECT
> dbo.Fun_Email_getLinkAccountNo('" + strSenderEmailAddress + "') AS
> ACCOUNTNO";
> DataSet ds= new DataSet();
> try
> {
> // calling the webservice
> ds =
> crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,
> objUser.userName, ThisAddIn.IPAddress);
> }
> catch (Exception Ex)
> {
> MessageBox.Show(Ex.Message);
> fnWriteErrorLog(Ex);
> return;
> }

> if (ds.Tables.Count > 0)
> {
> if (ds.Tables[0].Rows.Count > 0)
> {
> strAccountNo =
> ds.Tables[0].Rows[0]["ACCOUNTNO"].ToString();
> }
> else
> strAccountNo = "";
> }

> if (strAccountNo == "") //email address not
> found
> in db
> {
> objCRMGoldRecid.Value = "UNLINKED";
> objLinkedToContact.Value = "";
> objLinkedToCompany.Value = "";
> objLinkCheckBox.Value = false;
> }
> if (strAccountNo != "")
> {

> StringBuilder strRFC822 = new
> StringBuilder();
> strRFC822.Append(" ");
> string strMessageID = newMail.EntryID;

> strRFC822.Append(newMail.ReceivedTime.ToString("ddd, dd MMM yyyy
> hh:mm:ss")); //0
> strRFC822.Append("^ ");
> strRFC822.Append(strFrom); //1
> strRFC822.Append("^ ");
> strRFC822.Append(strSubject); //2
> strRFC822.Append("^ ");
> strRFC822.Append(strTo); //3
> strRFC822.Append("^ ");
> strRFC822.Append(strCC);//4
> strRFC822.Append("^ ");
> strRFC822.Append(strHasAttachment);//5
> strRFC822.Append("^ <");
> strRFC822.Append(strMessageID);//6
> strRFC822.Append(">");
> strRFC822.Append("^ ");
> strRFC822.Append(strMsgBody);//7
> strRFC822.Append("^ ");

> string oldFileName = string.Empty;
> string extn = string.Empty;
> string FileName = string.Empty;

> string emailattachments = "";

> strRFC822.Append(emailattachments);//8
> strRFC822.Append("^ ");

> strRFC822.Append(newMail.BodyFormat.ToString());//9

> if (strSubject.Length > 80)
> strSubject = strSubject.Substring(0,
> 80);
> string strRecdOnDate =
> newMail.ReceivedTime.ToString();

> sqlQuery = "SELECT companyid FROM
> tblcompanycontact WHERE accountno='" + strAccountNo + "'";
> try
> {
> //calling webservice
> ds =
> crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,
> objUser.userName.ToUpper(), ThisAddIn.IPAddress);
> }
> catch (Exception Ex)
> {
> MessageBox.Show(Ex.Message);
> fnWriteErrorLog(Ex);
> return;
> }

> //create new database record
> crmEZService.EmailMessage objEmailMessage =
> new CRMGoldOutlook.crmEZService.EmailMessage();
> objEmailMessage.recID = "";
> objEmailMessage.Flags = "";
> objEmailMessage.lopRecId = "";
> objEmailMessage.Folder = strFolderType;
> objEmailMessage.Folder2 = "";
> objEmailMessage.MessageID = strMessageID;
> objEmailMessage.Attachment =
> strHasAttachment;
> objEmailMessage.userId =
> objUser.userName.ToUpper();
> objEmailMessage.MailSize =
> newMail.Size.ToString();
> objEmailMessage.MailDate =
> DateTime.Parse(strRecdOnDate).ToString("yyyy-MM-dd");
> objEmailMessage.MailTime =
> newMail.ReceivedTime.ToString("HH:mm");
> objEmailMessage.MailRef = strSubject;
> objEmailMessage.RFC822 =
> strRFC822.ToString();
> objEmailMessage.contactID = strAccountNo;
> objEmailMessage.linkRecId = "";
> string MAILBOXRECID = string.Empty;

> try
> {
> //a new id is generated and returned by webservice
> MAILBOXRECID =
> crmService.createNewCRMObject(ThisAddIn.SessionID, objEmailMessage,
> ThisAddIn.objUser.userName.ToUpper(), ThisAddIn.IPAddress);
> }
> catch (Exception Ex)
> {
> MessageBox.Show(Ex.Message);
> fnWriteErrorLog(Ex);
> return;
> }

> sqlQuery = "SELECT ISNULL(company,'')as
> Company, ISNULL(contact,'') as Contact FROM contact1 WHERE accountno='" +
> strAccountNo + "'";
> try
> {
> ds =
> crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,
> objUser.userName.ToUpper(), ThisAddIn.IPAddress);
> }
> catch (Exception Ex)
> {
> MessageBox.Show(Ex.Message);
> fnWriteErrorLog(Ex);
> return;
> }

> // From here onwards, if there are no 'Rules and Alerts' specifed to
> direct
> the received mails to custom folder, the values are assigned
> // perfectly to UserProperties. But
> when
> there are rules mentioned to move the received mail to a user created
> 'Personal folder', then
> // the following error is thrown 'The operation cannot be performed
> because the message has been changed.' and the values are not fed
> // into the user properties.

> if (ds.Tables.Count > 0)
> {
> if (ds.Tables[0].Rows.Count > 0)
> {
> if (objCRMGoldRecid != null)
> {
> objCRMGoldRecid.Value =
> MAILBOXRECID;
> }
> objLinkedToContact.Value =
> ds.Tables[0].Rows[0]["Contact"].ToString();
> objLinkedToCompany.Value =
> ds.Tables[0].Rows[0]["Company"].ToString();
> objLinkCheckBox.Value = true;

> }
> }

> newMail.Save();

> }
> }

> }

> catch (Exception Ex)
> {
> MessageBox.Show(Ex.Message);
> fnWriteErrorLog(Ex);
> }

> }

> Thanks in advance.
>
 
P

Problem with UserProperty of mail object

Re: UserProperty of mail object problem while dealing with custom

hi Ken,

Using a new thread to access the Outlook object model was the main

problem for me to get the error 'The operation cannot be performed because

the message has been changed.' I removed that new thread and called

'fnNewMailRecv()' directly and it worked great without that error.

A ton of thanks to you for your wonderful support.

Thanks & Regards,

Varma.
wrote:


> You're using a new thread to access the Outlook object model, which is
> really, really bad. That is not supported and will cause Outlook to crash or
> hang in most cases. Get rid of that and localize where the problem is coming
> in your code. You need to show only the relevant code, no one is going to
> want to wade through all that code to try to find problems.

> >

>

> "Problem with UserProperty of mail object"
> <ProblemwithUserPropertyofmailobject> wrote in
> message news:1228956D-3C18-430B-BA46-1C9B0BF496BB@microsoft.com...
> > hi,
> > The error i come across while dealing with saving the
> > UserProperties of mails being directed to custom folders is 'The operation
> > cannot be performed because the message has been changed.'
> > The following is my code.
> > // this is called in 'ThisAddIn_Startup' method whenver a new mail is
> > received
> > this.Application.NewMailEx += new
> > Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
> > // the definition for 'Application_NewMailEx' is as follows
> > void Application_NewMailEx(string EntryIDCollection) //autolinking
> > {
> > if (strAutoLink == "ON")
> > {
> > string[] entries = EntryIDCollection.Split(',');
> > for (int c = 0; c < entries.Length; c++)
> > {
> > objMailItems =
> > (Outlook.MailItem)objNamesSpace.GetItemFromID(entries.GetValue(c).ToString(),
> > objInbox.StoreID);
> > threadMail = new Thread(new ThreadStart(fnNewMailRecv));
> > threadMail.Start();
> > }
> > }
> > }
> > //the definition for 'fnNewMailRecv()' is as follows
> > public void fnNewMailRecv()
> > {
> > try
> > {
> > Outlook.MailItem newMail = objMailItems;
> > currentMail = objMailItems;
> > GenModClass objGenMod = new GenModClass();
> > bool toLink = ThisAddIn.bLinkInCRM;
> > string strSenderName = newMail.SenderName.ToString();
> > string strUserName = objUser.userName.ToUpper();
> > Outlook.NameSpace objOUTLOOKNS =
> > this.Application.GetNamespace("MAPI");
> > Outlook.UserProperty objCRMGoldRecid;
> > Outlook.UserProperty objLinkedToContact;
> > Outlook.UserProperty objLinkedToCompany;
> > Outlook.UserProperty objLinkCheckBox;
> > newMail.Save();
> > objCRMGoldRecid = newMail.UserProperties.Add("RECID",
> > Outlook.OlUserPropertyType.olText, true, System.Reflection.Missing.Value);
> > objLinkedToContact = newMail.UserProperties.Add("Linked
> > to Contact", Outlook.OlUserPropertyType.olText, true,
> > System.Reflection.Missing.Value);
> > objLinkedToCompany = newMail.UserProperties.Add("Linked
> > to Company", Outlook.OlUserPropertyType.olText, true,
> > System.Reflection.Missing.Value);
> > objLinkCheckBox = newMail.UserProperties.Add("Is
> > Linked", Outlook.OlUserPropertyType.olYesNo, true,
> > System.Reflection.Missing.Value);
> > string strSenderEmailAddress = "";
> > if (newMail.SenderEmailAddress != null)
> > {
> > strSenderEmailAddress =
> > newMail.SenderEmailAddress.ToString();
> > string strFrom = strSenderEmailAddress == null ? ""
> > : strSenderEmailAddress;
> > string strTo = newMail.To == null ? "" :
> > newMail.To;
> > string strCC = newMail.CC == null ? "" :
> > newMail.CC;
> > string strBcc = newMail.BCC == null ? "" :
> > newMail.BCC;
> > string strSubject = newMail.Subject == null ? "" :
> > newMail.Subject;
> > if (strSubject.Length > 80)
> > strSubject = strSubject.Substring(0,
> > 80).ToString();
> > string strMsgBody = newMail.HTMLBody == null ? "" :
> > newMail.HTMLBody;
> > string strImp = newMail.Importance.ToString();
> > string strAccountNo=string.Empty;
> > //gnerating some id
> > string strMailBoxRecID =
> > objGenMod.GenerateRecId().ToString(); string
> > strHasAttachment = (newMail.Attachments.Count > 0) ? "Yes" : "No";
> > //to get a user's account no from my database
> > string sqlQuery = "SELECT
> > dbo.Fun_Email_getLinkAccountNo('" + strSenderEmailAddress + "') AS
> > ACCOUNTNO";
> > DataSet ds= new DataSet();
> > try
> > {
> > // calling the webservice
> > ds =
> > crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,
> > objUser.userName, ThisAddIn.IPAddress);
> > }
> > catch (Exception Ex)
> > {
> > MessageBox.Show(Ex.Message);
> > fnWriteErrorLog(Ex);
> > return;
> > }
> > if (ds.Tables.Count > 0)
> > {
> > if (ds.Tables[0].Rows.Count > 0)
> > {
> > strAccountNo =
> > ds.Tables[0].Rows[0]["ACCOUNTNO"].ToString();
> > }
> > else
> > strAccountNo = "";
> > }
> > if (strAccountNo == "") //email address not
> > found
> > in db
> > {
> > objCRMGoldRecid.Value = "UNLINKED";
> > objLinkedToContact.Value = "";
> > objLinkedToCompany.Value = "";
> > objLinkCheckBox.Value = false;
> > }
> > if (strAccountNo != "")
> > {
> > StringBuilder strRFC822 = new
> > StringBuilder();
> > strRFC822.Append(" ");
> > string strMessageID = newMail.EntryID;
> > strRFC822.Append(newMail.ReceivedTime.ToString("ddd, dd MMM yyyy
> > hh:mm:ss")); //0
> > strRFC822.Append("^ ");
> > strRFC822.Append(strFrom); //1
> > strRFC822.Append("^ ");
> > strRFC822.Append(strSubject); //2
> > strRFC822.Append("^ ");
> > strRFC822.Append(strTo); //3
> > strRFC822.Append("^ ");
> > strRFC822.Append(strCC);//4
> > strRFC822.Append("^ ");
> > strRFC822.Append(strHasAttachment);//5
> > strRFC822.Append("^ <");
> > strRFC822.Append(strMessageID);//6
> > strRFC822.Append(">");
> > strRFC822.Append("^ ");
> > strRFC822.Append(strMsgBody);//7
> > strRFC822.Append("^ ");
> > string oldFileName = string.Empty;
> > string extn = string.Empty;
> > string FileName = string.Empty;
> > string emailattachments = "";
> > strRFC822.Append(emailattachments);//8
> > strRFC822.Append("^ ");
> > strRFC822.Append(newMail.BodyFormat.ToString());//9
> > if (strSubject.Length > 80)
> > strSubject = strSubject.Substring(0,
> > 80);
> > string strRecdOnDate =
> > newMail.ReceivedTime.ToString();
> > sqlQuery = "SELECT companyid FROM
> > tblcompanycontact WHERE accountno='" + strAccountNo + "'";
> > try
> > {
> > //calling webservice
> > ds =
> > crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,
> > objUser.userName.ToUpper(), ThisAddIn.IPAddress);
> > }
> > catch (Exception Ex)
> > {
> > MessageBox.Show(Ex.Message);
> > fnWriteErrorLog(Ex);
> > return;
> > }
> > //create new database record
> > crmEZService.EmailMessage objEmailMessage =
> > new CRMGoldOutlook.crmEZService.EmailMessage();
> > objEmailMessage.recID = "";
> > objEmailMessage.Flags = "";
> > objEmailMessage.lopRecId = "";
> > objEmailMessage.Folder = strFolderType;
> > objEmailMessage.Folder2 = "";
> > objEmailMessage.MessageID = strMessageID;
> > objEmailMessage.Attachment =
> > strHasAttachment;
> > objEmailMessage.userId =
> > objUser.userName.ToUpper();
> > objEmailMessage.MailSize =
> > newMail.Size.ToString();
> > objEmailMessage.MailDate =
> > DateTime.Parse(strRecdOnDate).ToString("yyyy-MM-dd");
> > objEmailMessage.MailTime =
> > newMail.ReceivedTime.ToString("HH:mm");
> > objEmailMessage.MailRef = strSubject;
> > objEmailMessage.RFC822 =
> > strRFC822.ToString();
> > objEmailMessage.contactID = strAccountNo;
> > objEmailMessage.linkRecId = "";
> > string MAILBOXRECID = string.Empty;
> > try
> > {
> > //a new id is generated and returned by webservice
> > MAILBOXRECID =
> > crmService.createNewCRMObject(ThisAddIn.SessionID, objEmailMessage,
> > ThisAddIn.objUser.userName.ToUpper(), ThisAddIn.IPAddress);
> > }
> > catch (Exception Ex)
> > {
> > MessageBox.Show(Ex.Message);
> > fnWriteErrorLog(Ex);
> > return;
> > }
> > sqlQuery = "SELECT ISNULL(company,'')as
> > Company, ISNULL(contact,'') as Contact FROM contact1 WHERE accountno='" +
> > strAccountNo + "'";
> > try
> > {
> > ds =
> > crmService.executeCustomQuery(ThisAddIn.SessionID, sqlQuery,
> > objUser.userName.ToUpper(), ThisAddIn.IPAddress);
> > }
> > catch (Exception Ex)
> > {
> > MessageBox.Show(Ex.Message);
> > fnWriteErrorLog(Ex);
> > return;
> > }
> > // From here onwards, if there are no 'Rules and Alerts' specifed to
> > direct
> > the received mails to custom folder, the values are assigned
> > // perfectly to UserProperties. But
> > when
> > there are rules mentioned to move the received mail to a user created
> > 'Personal folder', then
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Using .Restrict with a UserProperty in an Exchange folder Outlook VBA and Custom Forms 4
S Userproperty question Outlook VBA and Custom Forms 1
L Retrieving the DisplayFormat for a UserProperty using VB Outlook VBA and Custom Forms 3
R Outlook 2007: Userproperty missing after sending Outlook VBA and Custom Forms 3
R Sent emails show iCloud mail account not the alias Using Outlook 1
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
P Importing other e-mail accounts into Outlook Using Outlook 1
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
O Exchange Sync period only (e.g. last years mail) Using Outlook 0
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
M Convertor for Outlook Express Mail Store (.dbx) to Outlook Mail Store (.pst) Using Outlook 0
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
J E-mail held in Outbox while Minimized Using Outlook 3
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
T Outlook creates a copie of every mail I send Using Outlook.com accounts in Outlook 4
N Please advise code received new mail Using Outlook 0
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
L Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
MrMayor SENT mail not reloading to top?? Using Outlook 4
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
ThinkToday Calculate reply time of outlook mail Using Outlook 1
B Outlook 2010 Opening Mail Attachment Using Outlook 2
e_a_g_l_e_p_i Is it possible it set the fonts used to read incoming mail Using Outlook 25
D Mail in Sent Items Gone Using Outlook 12
M Managing Gmail "All Mail" sync issues with IMAP Using Outlook 1
GregS Outlook 2016 Sent Mail absent from Sent Mail or Sent Items Folders Using Outlook 4
GregS Why is Outlook 2016 mail in Outlook.com? Using Outlook 1
S Outlook not receiving mail Using Outlook 1
Commodore Outlook (2013) issues with icloud.com mail Using Outlook 0
GregS Outlook 2016 iPhone won't download Outlook 2016 Mail. Using Outlook 0
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
oliv- How to distinguish whether mail is incoming or outgoing? Outlook VBA and Custom Forms 2
W Receiving mail for account that has been deleted Using Outlook 2
H In outlook 365 POP mail Inbox, email takes a long time or never arrives. Using Outlook 1
Z Add text to auto-forwarded e-mail Outlook VBA and Custom Forms 4
K HOW TO FIX AOL MAIL ISSUES? Using Outlook 0
O How to prevent CC from showing when creating a new mail? Using Outlook 1
I Junk Mail and PersonMetadata Using Outlook 2
T 3 months of archived e-mail is missing Using Outlook 1

Similar threads

Top