Creating and sending a mail is a very simple task. However, while writing custom applications with form region fetching data from web services or other business object layers, often it is a big performance overhead to fetch these info on form region load. Rather, it's much better to sync up with Outlook's Send/ Receive process and pre-fetch the data and cache it accordingly. Oops, now this is simple too but trust me, difficult to locate this island of information. Lets see how it is done:
A simple routine to create a mail is as follows:
Mail
NameSpace oNameSpace;
oNameSpace= oApp.GetNamespace("MAPI");
oNameSpace.Logon(<Profile>,<Password>,false,false);
MailItem newMail = Application.CreateItem(Outlook.OlItemType.olMailItem);
newMail.To = toValue;
newMail.Subject = subjectValue;
newMail.Body = bodyValue;
newMail.SaveSentMessageFolder = oOutboxFolder;
newMail.Send();
To sync with Outlook's event, try this out:
Syncing up with Send Receive
SyncObject mySyncObject = this.Application.Session.SyncObjects[1];
mySyncObject.SyncStart += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_SyncStartEventHandler(mySyncObject_SyncStart);
mySyncObject.SyncEnd += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_SyncEndEventHandler(mySyncObject_SyncEnd);
mySyncObject.OnError += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_OnErrorEventHandler(mySyncObject_OnError);
void mySyncObject_SyncStart()
{
//TODO--MessageBox.Show("SyncStart");
}
void mySyncObject_SyncEnd()
//TODO--MessageBox.Show("SyncEnd");
void mySyncObject_OnError(int Code, string Description)
//TODO--MessageBox.Show("SyncError");
Simple and fun. Hope it helps you folks.