从C#启动电子邮件应用程序(MAPI)(附件) [英] Launching email application (MAPI) from C# (with attachment)

查看:1434
本文介绍了从C#启动电子邮件应用程序(MAPI)(附件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去,我已经使用MAPISendMail则来自同一个文件附件C ++应用程序推出的Outlook(或任何所需的MAPI电子邮件应用是)。 (类似于说Microsoft Word中的发送电子邮件功能)。

In the past I have used MAPISendMail to launch Outlook (or whatever the desired MAPI email application was) from a C++ application with a file attachment. (Similar to say Microsoft Word's Send Email functionality).

我需要做的从C#应用程序相媲美,并具有在XP,Vista中,Server 2008中运行时,它的工作(和Windows 7我想)。

I need to do the equivalent from a C# application and to have it work when running on XP, Vista, Server 2008 (and Windows 7 I suppose).

MAPISendMail则是在Vista / 2008,因为它总是返回MAPI_ E_FAILURE当Outlook正在运行,并在托管代码中不支持MAPI不走。
检查此修复程序后,即使:
http://support.microsoft.com/kb/939718
我不能让它可靠地工作。

MAPISendMail is a no go under Vista/2008 as it always returns MAPI_ E_FAILURE when Outlook is running and MAPI is not supported in managed code. Even after checking this fix: http://support.microsoft.com/kb/939718 I can't get it to reliably work.

我知道,微软Word和放大器; ADOBE READER 9可以同时启动Outlook与Vista下的附件。

AC#兼容的解决方案将是首选,但我很乐意与任何该作品(没有使用MAPI)。我似乎无法查找当前的解决方案是什么。对堆栈溢出的现有答案似乎都不要么支付本

编辑:

我知道MAPI和C#不在一起工作,所以我就以一个C / C ++的解决方案,在Vista中工作和Server 2008时,不会以管理员身份运行。请参阅Adobe阅读器9和; Microsoft Word作为这项工作的例子。

I am aware MAPI and C# do not work together, so I will take a C/C++ solution that works in Vista and Server 2008 when NOT running as administrator. See Adobe Reader 9 & Microsoft Word as examples that work.

推荐答案

在工作中,我们已经成功地做​​到了这一点使用VSTO。

At work we have successfully done this using VSTO.

下面是我们对VISTA与Outlook 2007中运行某些线路的一个片段:(代码是VB.net)

Here is a snippet of some lines we have running on VISTA with Outlook 2007: (the code is in VB.net).

请注意做某些事情的前景对象时使用是安全锁定。 (为解决,身体和其他属性标记为安全风险)。我们使用一个第三方组件(赎回)去解决这个安全性。如果你不使用某种形式的安全管理器,Outlook将给予一点点弹出的东西外面正试图访问它,你可以给它在一段时间内获得。

Note that the usage is security locked when doing certain things to the outlook object. (to address, body and other properties marked as security risks). We use a 3rd party component (Redemption) to go around this security. If you dont use a security manager of some sort, outlook will give a little popup that something outside is trying to access it and you can give it access in a period of time.

Outlook界面的导入。

The import of the Outlook interface.

Imports Outlook = Microsoft.Office.Interop.Outlook

这例子是给你一些指导,而不是一个完整的工作的例子。

This example is to give you some direction, not a full working example.

dim MailItem As Microsoft.Office.Interop.Outlook.MailItem

' Lets initialize outlook object '
MailItem = OutlookSession.Application.CreateItem(Outlook.OlItemType.olMailItem)
MailItem.To = mailto

MailItem.Subject = communication.Subject
MailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
MailItem.HTMLBody = htmlBody

MailItem.Attachments.Add(filename, Outlook.OlAttachmentType.olByValue)

' If True is supplied to Display it will act as modal and is executed sequential. '
SafeMail.Display(True)



在上面的例子中的OutlookSession从该来属性:

The OutlookSession in the above example is coming from this Property:

    Public ReadOnly Property OutlookSession() As Outlook.NameSpace
        Get
            If Not OutlookApplication Is Nothing Then
                Return OutlookApplication.GetNamespace ("MAPI")
            Else
                Return Nothing
            End If
        End Get
    End Property

你可以它使用MAPI内此看到的。

As you can see it is using MAPI inside for this.

好运气吧。

这篇关于从C#启动电子邮件应用程序(MAPI)(附件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆