C# 使用outlook从网站打开现有电子邮件
我们正在将一些电子邮件从Exchange服务器的特定收件箱保存到某种跟踪系统。用户使用浏览器查看此跟踪系统 我现在要做的是在一个网页上生成一个链接,当然可以在客户端的Outlook 2010中打开现有的电子邮件 要生成此链接,我拥有电子邮件/项目的所有必要信息(使用Microsoft.Exchange.WebServices) 那怎么做呢 好的,到目前为止我有: 将exchange server中的ewsId(exchange server上邮件的id)转换为outlook的entryid。这是通过使用EWS的ConvertId方法完成的C# 使用outlook从网站打开现有电子邮件,c#,html,outlook,exchangewebservices,C#,Html,Outlook,Exchangewebservices,我们正在将一些电子邮件从Exchange服务器的特定收件箱保存到某种跟踪系统。用户使用浏览器查看此跟踪系统 我现在要做的是在一个网页上生成一个链接,当然可以在客户端的Outlook 2010中打开现有的电子邮件 要生成此链接,我拥有电子邮件/项目的所有必要信息(使用Microsoft.Exchange.WebServices) 那怎么做呢 好的,到目前为止我有: 将exchange server中的ewsId(exchange server上邮件的id)转换为outlook的entryid。这是
现在我遇到了一个问题,当我尝试用outlook加载邮件时,出现了一个错误“元素无法打开。请重试”。您好,我认为这将帮助您 基本上有三种方法
- 使用
打开outlook应用程序mailto
- 使用传统的SMTP发送邮件
- 使用Outlook对象库打开Outlook以及作为应用程序组成部分添加的附件李>
<A href=”mailto:Bob@somewhere.com
?Cc:Roxy@righthere.com
&Subject:Using Mailto to send mails&Body:this is a test”>.
使用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对象库
下面是使用MS outlook对象库将outlook与VB.Net集成的一小段代码
- 首先实例化Outlook应用程序对象李>
- 确保在项目引用中添加引用李>
- 右键单击解决方案资源管理器中的引用。添加“Microsoft Outlook 10.0对象库” 公共函数OutlookCall() '以Outlook应用程序为例 Dim oOutlook作为新Outlook.Application()显示 端函数
- 计算机上应安装Microsoft Outlook李>
- 假定Microsoft Outlook是默认的邮件客户端应用程序
- 如果outlook发送项目的现有实例已在运行,它仍将创建新邮件李>
这个vl帮助u好的,我找到了一个解决方案,在这里发布了我的代码: 在服务器端(使用exchange webservice的c#):
私有静态字符串GetOutlookEntryId(EmailMessage、ExchangeService esb){
AlternateId ewsId=新的AlternateId(IdFormat.ewsId,message.Id.ToString(),“电子邮件。address@test.de" );
AlternateIdBase entryId=esb.ConvertId(ewsId,IdFormat.entryId);
返回Base64StringToHexString(((AlternateId)entryId).UniqueId);
}
公共静态字符串Base64StringToHexString(字符串base64String){
byte[]bytes=System.Convert.FromBase64String(base64String);
StringBuilder sbHexString=新的StringBuilder();
for(int i=0;i
在客户端(Internet explorer、已安装Outlook、vbscript):
亚openMailInOutlook
mailID=“从服务器端的exchange id转换而来的条目id”
设置olApp=createobject(“Outlook.Application”)
set session=olApp.session
set originalMailItem=session.GetItemFromID(mailID)
原件显示
设置olNs=Nothing
设置olApp=Nothing
端接头
我遇到的问题是,我有一封现有的电子邮件,我想用outlook打开它。那么,如何使用Microsoft Outlook 10.0对象库获取该电子邮件呢?这真是太棒了!
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`
'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()
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();
}
<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