Tuesday, October 18, 2011

Create a Mail Item by Using a Message Template

//namespace (add Microsoft.Office.Interop.Outlook.dll)



using Outlook = Microsoft.Office.Interop.Outlook;
//C# code : will create new mail message using predefined template
private void CreateNewMessageUsingTemplate()
{
    Outlook.Folder folder =
        Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
    Outlook.MailItem mail =
        Application.CreateItemFromTemplate(
        @"c:\templageName.oft", folder) as Outlook.MailItem;
    mail.Subject = "Using Template";
    mail.Save();
}
//C# code : will create new mail message using predefined template
Private Sub CreateNewMessageUsingTemplate()
    Dim folder As Outlook.Folder = _
        CType(Application.Session.GetDefaultFolder( _
        Outlook.OlDefaultFolders.olFolderDrafts), Outlook.Folder)
    Dim mail As Outlook.MailItem = _
        CType(Application.CreateItemFromTemplate( _
        "c:\templateName.oft", folder), Outlook.MailItem)
    mail.Subject = "Using Template"
    mail.Save()
End Sub

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

The Code 39 error occurs when Windows is unable to load the device driver for a specific hardware device. This typically indicates that the driver is corrupted, missing, or incompatible

The Code 39 error occurs when Windows is unable to load the device driver for a specific hardware device. This typically indicates that the...