Creating New Email Programatically

7

78.sergey

Hi All

I am new to this Outlook development through VSTO and needed a quick
clarification.

I am creating new emails in my app (using VSTO & C#) programatically
and am able to do that but was not sure if this is the best way to do
it:

Here is what I do:

public Outlook.MAPIFolder outBoxfolder;
outBoxfolder =
app.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
Outlook.MailItem newMailItem =
(Outlook.MailItem)filter.outBoxfolder.Items.Add(Outlook.OlItemType.olMailItem);
newMailItem.Subject = mycopiedItem.Subject + " (Please treat this as
Private)";
newMailItem.To = "aaa.hotmail.com";
newMailItem.CC = string.Empty;
newMailItem.BCC = string.Empty;

The above code works but Please let me know if there is a better way
to create new emails.
 
D

Dmitry Streblechenko

There is no better or worse way: it all depends on what you arae trying to
achieve.
Use MAPIFolder.Items.Add if you arae creating gan item in a particular
folder (keep in midnd that Outlook always creates mail items in teh Drafts
fodler - bug) or call Application.CreateItme() if you wnat the new item to
be created in the default folder for the specified item kind.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top