Microsoft Office Tutorials and References
In Depth Information
Email is an electronic form of storing information that can be shared with people via
an electronic communication system. You can write, send, and receive information
without using paper, and communicate through electronic systems by using a digital
copy of the information.
You can do many email operations through VSTO programming, such as composing
mail items at runtime using Office objects. Let's create a new mail that has a Subject ,
To, Address and few other properties, by using the VSTO Outlook MailItem object.
Open Visual Studio 2008 and create a new solution, as explained earlier.
Write the following code, which will dynamically create a mail item, inside
the ThisAddIn.cs file:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
// Outlook mailitem object to compose new mail
Outlook.MailItem PacktMailItem = (Outlook.MailItem)this.
// Set the To address property value
PacktMailItem.To = "email@example.com";
// Set the Subject property value
PacktMailItem.Subject = "Mail from PacktPub Editor";
// Set the Body property value
PacktMailItem.Body = "Your book is ready to buy!";
// Set the Importance level for the mail
PacktMailItem.Importance = Outlook.OlImportance.
// If parameter is set to false compose mail won't display
// To send the composed mailitem
// ((Outlook._MailItem) PacktMailItem).Send();