0

我的系统上运行着窗口应用程序,我可以在其中通过任何地方发送邮件,但我想将我的应用程序集成到 Outlook。

1.已发送邮件应显示在outlook已发送邮件文件夹中。2.如果邮件发送失败,它应该显示在outlook的发件箱文件夹中

4

1 回答 1

1

Go through following code:

Outlook.Application oApp = new Outlook.Application();

if (this.listViewContacts.SelectedItems != null &&
this.listViewContacts.SelectedItems.Count > 0)
{
Outlook.ContactItem oRecip = (Outlook.ContactItem)
(this.listViewContacts.SelectedItems[0].Tag);

Outlook.MailItem email = (Outlook.MailItem)
(oApp.CreateItem(Outlook.OlItemType.olMailItem));
email.Recipients.Add(oRecip.Email1Address);
email.Subject = "Just wanted to say...";
email.Body = "Have a great day!";

if (MessageBox.Show(
"Are you sure you want to send a good day message to " +
oRecip.Email1DisplayName + "?", "Send?",
MessageBoxButtons.OKCancel)
== DialogResult.OK)
{
try
{
((Outlook.MailItem)email).Send();
MessageBox.Show("Email sent successfully.", "Sent");
}
catch (Exception ex)
{
MessageBox.Show("Email failed: " + ex.Message,
"Failed Send");
}
}

oRecip = null;
email = null;
}

Referance Link:

http://www.codeguru.com/csharp/csharp/cs_misc/e-mail/article.php/c14293/Microsoft-Outlook-Integration-with-CNET.htm#page-2

Step by step implementation and explaination is given in this link.

Hope its helpful.

于 2013-05-15T04:38:42.713 回答