Reputation: 2785
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".
Upvotes: 2
Views: 3941
Reputation: 66
Hi I think This Will help U
Basically there are three ways of doing this.
mailto
to open the outlook 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.
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:
this vl help u
Upvotes: 1
Reputation: 2785
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
Upvotes: 1