从网站上使用 Outlook 打开现有电子邮件

发布于 2024-12-19 05:17:45 字数 391 浏览 4 评论 0原文

我们正在将一些电子邮件从 Exchange 服务器的特定收件箱保存到某种跟踪系统中。用户使用浏览器查看该跟踪系统。

我现在想做的是在网页上生成一个链接,当然可以在客户端上的 Outlook 2010 中打开现有电子邮件。

为了生成此链接,我拥有电子邮件/项目的所有必要信息(使用 Microsoft.Exchange.WebServices)。

那么如何做到这一点呢?

好的,到目前为止我所拥有的: 将 Exchange 服务器上的 ewsId(Exchange 服务器上邮件的 ID)转换为 Outlook 的 EntryID。这是通过使用 EWS 的 ConvertId 方法来完成的。

现在我遇到的问题是,当我尝试使用 Outlook 加载邮件时,出现错误“无法打开元素。请重试”。

We are saving some Emails from a specific Inbox of an Exchange Server to some kind of tracking system. User look at this tracking system by using the browser.

What I am trying to do now is to generate a link on a webpage which opens an existing email in Outlook 2010 on the client of course.

To generate this link I have all necessary information of the email/item (using Microsoft.Exchange.WebServices).

So how to do that?

ok what i have so far:
convert the ewsId (id of the mail on exchange server) from exchange server to entryid of outlook. this is done by using the ConvertId method of EWS.

now i have the problem that when i try to load the mail with outlook i get an error "element could not be opened. try again".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈下烟灰 2024-12-26 05:17:45

好的,我找到了一个解决方案,在这里发布我的代码:

在服务器端(带有交换Web服务的c#):

    private static String GetOutlookEntryId( EmailMessage message, ExchangeService esb ) {
        AlternateId ewsId = new AlternateId( IdFormat.EwsId, message.Id.ToString(), "[email protected]" );
        AlternateIdBase entryId = esb.ConvertId( ewsId, IdFormat.EntryId );
        return Base64StringToHexString( ( (AlternateId)entryId ).UniqueId );
    }

    public static String Base64StringToHexString( String base64String ) {
        byte[] bytes = System.Convert.FromBase64String( base64String );

        StringBuilder sbHexString = new StringBuilder();
        for( int i = 0; i < bytes.Length; i++ ) {
            sbHexString.Append( bytes[i].ToString( "X2" ) );
        }
        return sbHexString.ToString();
    }

在客户端(Internet Explorer,安装了Outlook,vbscript):

<script language="vbscript">
sub openMailInOutlook
    mailID = "the entry id converted from exchange id on the server side"

    set olApp = createobject("Outlook.Application")

    set session = olApp.Session
    set originalMailItem = session.GetItemFromID( mailID )

    originalMailItem.Display

    set olNs = Nothing
    set olApp = Nothing
end sub

ok i found a solution an post my code here:

on the serverside (c# with exchange webservice):

    private static String GetOutlookEntryId( EmailMessage message, ExchangeService esb ) {
        AlternateId ewsId = new AlternateId( IdFormat.EwsId, message.Id.ToString(), "[email protected]" );
        AlternateIdBase entryId = esb.ConvertId( ewsId, IdFormat.EntryId );
        return Base64StringToHexString( ( (AlternateId)entryId ).UniqueId );
    }

    public static String Base64StringToHexString( String base64String ) {
        byte[] bytes = System.Convert.FromBase64String( base64String );

        StringBuilder sbHexString = new StringBuilder();
        for( int i = 0; i < bytes.Length; i++ ) {
            sbHexString.Append( bytes[i].ToString( "X2" ) );
        }
        return sbHexString.ToString();
    }

on the client side (Internet explorer, Outlook installed, vbscript):

<script language="vbscript">
sub openMailInOutlook
    mailID = "the entry id converted from exchange id on the server side"

    set olApp = createobject("Outlook.Application")

    set session = olApp.Session
    set originalMailItem = session.GetItemFromID( mailID )

    originalMailItem.Display

    set olNs = Nothing
    set olApp = Nothing
end sub

倾听心声的旋律 2024-12-26 05:17:45

你好,我认为这会对你有帮助

基本上有三种方法可以做到这一点。

  • 使用 mailto 打开 Outlook 应用程序
  • 使用传统的 SMTP 发送邮件
  • 使用 Outlook 对象库打开 Outlook 以及添加的附件作为应用程序的组成部分。

使用Mailto Link

<A href=”mailto:[email protected]
         ?Cc:[email protected]
         &Subject:Using Mailto to send mails&Body:this is a test”>. 

这是一种很俗气的方法。将属性与 mailto 一起传递,

但是如果您想在 VB.Net LinkLabel 中使用它。您可以通过这种方式

Dim strURL as String strURL = “mailto:[email protected]
                              ?Cc:[email protected]
                              &Subject:Using Mailto to send mails&Body:this is a test” 
Process.Start(strURL)

使用 SMTP 发送邮件

在开始编码之前,请确保导入相关的命名空间

Imports System.Web.Mail

这是代码

Public Function SMTPCall()
    Dim strTo As String
    Dim strFrom As String 
    Dim strBody As String 
    Dim strSubject As String 
    strTo = "[email protected]" 

    'Make sure you set the from address, 
    'some SMTP servers wouldn't send a mail without the FROM address 
    strFrom = "[email protected]" `
    strBody = "Test on Sending Mail"` 
    strSubject = "Did this mail reach you yet?" `
    SmtpMail.Send(strFrom, strTo, strSubject, strBody) `
End Function`

看起来不错,但上述两种方法的限制是您无法发送附件。如果用户想要访问 Outlook 地址簿并向邮件发送附件怎么办?

使用 MSOutlook 对象库

下面是一小段使用 MS Outlook 对象库将 Outlook 与 VB.Net 集成的代码。

  • 首先实例化 Outlook 应用程序对象。
  • 确保在项目参考中添加参考。
  • 右键单击解决方案资源管理器中的“引用”。添加“Microsoft Outlook 10.0 对象库”。

    公共函数 OutlookCall()
    '以 Outlook 应用程序为例
    将 oOutlook 调暗为新 Outlook.Application()

    '创建 MailItem 的实例 
    将 oMailitem 变暗为 Outlook.MailItem`
    
    '创建附件的实例 
    变暗 oAttach As Outlook.Attachment
    oMailitem = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
    oMailitem.To =“[电子邮件受保护]”
    oMailitem.Cc =“[电子邮件受保护]”
    oMailitem.Subject = "电子邮件与 Outlook 和 VB.Net 集成"
    
    'txtFilepath 是包含附件路径的文本框。
    如果 (txtFilepath.Text = "") 那么
        MsgBox(“您没有附加文件”)
    别的
        '将文件路径附加到邮件项目 
        oMailitem.Attachments.Add(txtFilepath.Text)
    结束如果
    
    'PING...显示 Outlook 以及收件人、抄送、主题和附件 
    oMailitem.Display()
    

    结束函数

您可以使用此 Outlook 对象执行许多其他功能。希望这有帮助。

注意:

  • 计算机上应安装 Microsoft Outlook。
  • Microsoft Outlook 被假定为默认邮件客户端应用程序。
  • 如果 Outlook 发送项目的现有实例已在运行,它仍会创建新的邮件消息。

这个vl对你有帮助

Hi I think This Will help U

Basically there are three ways of doing this.

  • Using mailto to open the outlook Application
  • Using the traditional SMTP Send Mail
  • Using the Outlook Object Library to open the outlook along with an added attachment as an integral part of the application.

Using Mailto Link

<A href=”mailto:[email protected]
         ?Cc:[email protected]
         &Subject:Using Mailto to send mails&Body:this is a test”>. 

This is a cheesy way of doing it. Pass the attributes along with the mailto

However if you want to use this in a VB.Net LinkLabel. You can do it this way

Dim strURL as String strURL = “mailto:[email protected]
                              ?Cc:[email protected]
                              &Subject:Using Mailto to send mails&Body:this is a test” 
Process.Start(strURL)

Using SMTP Send Mail

Before you start coding make sure you import the related namespace

Imports System.Web.Mail

Here goes the code

Public Function SMTPCall()
    Dim strTo As String
    Dim strFrom As String 
    Dim strBody As String 
    Dim strSubject As String 
    strTo = "[email protected]" 

    'Make sure you set the from address, 
    'some SMTP servers wouldn't send a mail without the FROM address 
    strFrom = "[email protected]" `
    strBody = "Test on Sending Mail"` 
    strSubject = "Did this mail reach you yet?" `
    SmtpMail.Send(strFrom, strTo, strSubject, strBody) `
End Function`

Looks good, but the limitation with the above two methods is you cannot send an attachment. What if the user wants to access the outlook address book and also send the mail an attachment?

Using MSOutlook Object Library

Here’s a small piece of code for outlook integration with VB.Net using MS Outlook object Library.

  • First instantiate the Outlook application object.
  • Make sure you add the references in the Project References.
  • Right click on the References in the Solution Explorer. Add “Microsoft Outlook 10.0 Object Library”.

    public Function OutlookCall()
    'Take an instance of the Outlook App
    Dim oOutlook As New Outlook.Application()

    'Create an instance of the MailItem 
    Dim oMailitem As Outlook.MailItem`
    
    'Create an instance of the Attachment 
    Dim oAttach As Outlook.Attachment
    oMailitem = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
    oMailitem.To = “[email protected]”
    oMailitem.Cc = “[email protected]”
    oMailitem.Subject = "Email Integration with Outlook and VB.Net"
    
    'txtFilepath is a text box that contains the path for attachment.
    If (txtFilepath.Text = "") Then
        MsgBox ("You did not attach a file")
    Else
        'Attach the file Path to the Mail Item 
        oMailitem.Attachments.Add(txtFilepath.Text)
    End If
    
    'PING….Displays the Outlook along with the To,Cc,Subject and Attachment 
    oMailitem.Display()
    

    End Function

There are a lot of other features you can do with this outlook object. Hope this helps.

Note:

  • Microsoft Outlook should be the installed on the machine.
  • Microsoft Outlook is assumed as the default mail client application.
  • If an existing instance of outlook send item is already running, it would still create a new mail Message.

this vl help u

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文