Solved

issue with using outlook in vb.net

Posted on 2014-01-08
10
775 Views
Last Modified: 2014-01-21
I have a function where I am using outllok to save an email from a vb.net application which works fine in my development environment using visual studio but get the following error when I deploy to test environment which is using windows 2008 r2 and below is the error:

Message from webpage
---------------------------
problem in page load to the error: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

and below is my piece of code:
Imports outlook = Microsoft.Office.Interop.Outlook

 Public Sub testemail()
        Dim OutlookMessage As outlook.MailItem
        Dim AppOutlook As New outlook.Application

        Dim objNS As outlook._NameSpace = AppOutlook.Session
        Dim objFolder As outlook.MAPIFolder
        objFolder = objNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderDrafts)


        Try
            OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
            Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
            Recipents.Add("myemail@hotmail.com")

            OutlookMessage.Subject = "test"
            OutlookMessage.Body = "Testing outlook Mail"
            OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
            OutlookMessage.Save()
            ' OutlookMessage.Move(objFolder)
        Catch ex As Exception
            'MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line    
        Finally
            OutlookMessage = Nothing
            AppOutlook = Nothing
        End Try
end sub
0
Comment
Question by:welcome 123
  • 5
  • 5
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39768669
The obvious question is do you have Outlook installed on the server?
0
 

Author Comment

by:welcome 123
ID: 39768785
no, all I want is the user to sve an email in outlook and anybody has an idea using exchange webservices?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39768803
You would need to install Outlook on the service to use the COM library.

Using Exchange Web Services would be different from using Outlook interop library.  How much would you need to know about EWS?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39768820
If you need to understand a little about EWS, you can start here:

Exchange Web Services
http://www.codeproject.com/Articles/399015/Exchange-Web-Services

You would need to connect to the Exchange web service, create an EmailMessage, and call the Save method to save to the default folder.
0
 

Author Comment

by:welcome 123
ID: 39771876
It works fine in development but when I pushed it to the test server i am getting the below error :
I even installed the WES on the server.

Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:welcome 123
ID: 39771908
it work after I manually registed the dll but it takes a long time calling EWS, is there a way to speed up?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39771964
What is taking a long time (auto-discover, saving E-Mail message, ...?  

Can you show me code where it takes too much time?
0
 

Author Comment

by:welcome 123
ID: 39783956
I commented the line: 'service.AutodiscoverUrl(validateEmail, AddressOf ValidateRedirectionUrlCallback)
 and it still works and also speeds up other wise its way too slow and I don't know why this line is actually useed

 Public Sub SaveEmailMessage()

        Dim service As ExchangeService = Nothing
        Dim emailServiceURL As String = "https://mymailserver.somewhere.com/EWS/Exchange.asmx"
        Try
            If service Is Nothing Then
                service = New ExchangeService(ExchangeVersion.Exchange2010_SP1)
                service.Url = New Uri(emailServiceURL)
                service.UseDefaultCredentials = False
            End If
            Dim netcredit As New NetworkCredential("testusername", "testpassword", "testdomain")
            service.Credentials = netcredit
'service.AutodiscoverUrl(validateEmail, AddressOf ValidateRedirectionUrlCallback)
         
            'now send a test email
            'EmailMessage(message = New EmailMessage(service))
            Dim message = New EmailMessage(service)
            message.Subject = "Email from PCardTE"

            message.Body = SaveData().ToString
            ' message.Body.BodyType = BodyType.HTML

            message.ToRecipients.Add("abc@obm.state.oh.us")
                        message.Save()
            ' message.SendAndSaveCopy()
            '.BodyFormat = outlook.OlBodyFormat.olFormatHTML

            Catch ex As Exception


                Dim Err As New ErrorLog()
                Err.ErrorLog(Server.MapPath("~/Logs/ErrorLog"), ex.Message)
                JavaScriptSetFocus("Unable to save email due to the error: " & ex.Message)
            Finally
               
            End Try
    End Sub

[SouthMod: I've edited the URL above]
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39784041
If you want to discover the URL, then you would use the AutoDiscoverUrl method.  Since you are specifying the URL, then you don't need to use auto-discover.

Also, if you don't want to show the URL for your web service to the world, then you might want to ask an admin to remove that from the question (it's a good practice not to post sensitive information in a comment).
0
 

Author Comment

by:welcome 123
ID: 39786603
thanks for your comment, I didn't notice that in a hurry, usually I make everything look like a test , will email admin ASAP
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Framework versus framework 64 in IIS 8.5 5 99
Registering DLL 5 43
Entity Framework 3 46
Entity Framework 7 27
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now