打开现有的电子邮件与outlook从一个网站

本文关键字:网站 一个 outlook 电子邮件 | 更新日期: 2023-09-27 18:16:42

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

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

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

怎么做呢?

好的,我到目前为止有什么:将exchange服务器的ewsId (exchange服务器上的邮件id)转换为outlook的entryid。这是通过使用EWS的ConvertId方法完成的。

现在我有一个问题,当我尝试用outlook加载邮件时,我得到一个错误"元素无法打开"。再试一次"。

打开现有的电子邮件与outlook从一个网站

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

在服务器端(c# with exchange webservice):

    private static String GetOutlookEntryId( EmailMessage message, ExchangeService esb ) {
        AlternateId ewsId = new AlternateId( IdFormat.EwsId, message.Id.ToString(), "email.address@test.de" );
        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

你好,我想这对你有帮助

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

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

使用邮件链接

<A href=”mailto:Bob@somewhere.com
         ?Cc:Roxy@righthere.com
         &Subject:Using Mailto to send mails&Body:this is a test”>. 

这是一种俗气的做法。将属性与邮件一起传递到

但是如果你想在VB中使用它。净LinkLabel。你可以这样做

Dim strURL as String strURL = “mailto:Bob@somewhere.com
                              ?Cc:Roxy@righthere.com
                              &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 = "Bob@somewhere.com" 
    'Make sure you set the from address, 
    'some SMTP servers wouldn't send a mail without the FROM address 
    strFrom = "Roxy@righthere.com" `
    strBody = "Test on Sending Mail"` 
    strSubject = "Did this mail reach you yet?" `
    SmtpMail.Send(strFrom, strTo, strSubject, strBody) `
End Function`

看起来不错,但是上面两种方法的限制是不能发送附件。如果用户希望访问outlook地址簿并发送邮件附件,该怎么办?

使用MSOutlook对象库

这是outlook与VB集成的一小段代码。Net使用MS Outlook对象库。

  • 首先实例化Outlook应用对象。
  • 确保在Project references中添加了引用。
  • 右键单击解决方案资源管理器中的引用。添加"Microsoft Outlook 10.0对象库"。

    public Function OutlookCall()以Outlook应用程序为例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 = “Bob@somewhere.com”
    oMailitem.Cc = “Roxy@righthere.com”
    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()
    

    结束函数

你可以用这个outlook对象做很多其他的功能。希望对你有帮助。

注意:

  • Microsoft Outlook应该安装在机器上。
  • 假定Microsoft Outlook为默认邮件客户端应用程序。
  • 如果outlook send item的现有实例已经在运行,它仍然会创建一个新的邮件消息。