How to to add com references manually to aspx page?

Posted on 2005-04-28
Last Modified: 2012-06-27
How to to add com references manually to the aspx page?  I want to send email using Microsoft outlook from my aspx page, I have used some code as the following:

Dim obj as new Outlook.Application

but I got some compilation error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'Outlook.Application' is not defined.

Source Error:
Line 12: Sub btn_Click(sender as Object, e as System.EventArgs)
Line 13:  If  Request.Form("Email") <> "" Then
Line 14:     Dim outObj As New Outlook.Application
Line 15:      Dim Item As Outlook.MailItemClass
Line 16:      

Source File: http://localhost/mailTest.aspx    Line: 14

how to solve this problem?


Question by:kindy
    LVL 13

    Accepted Solution

    for this to work you need make refference with two objects, "Outlook.dll" and "stdole.dll", the reason your program doesn't work, might be "stdole.dll" if you already have "Outlook.dll" properly refferenced and if not then you need them both!

    Dim ol As New Outlook.Application()
    Dim ns As Outlook.NameSpace
    Dim fdMail As Outlook.MAPIFolder

    ns = ol.GetNamespace("MAPI")
    ns.Logon(, , True, True)  '// ns.Logon(Username, Password, ShowDialog, NewSession

    Dim newMail As Outlook.MailItem

    fdMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)

    newMail = fdMail.Items.Add(Outlook.OlItemType.olMailItem)
    newMail.Subject = subjectVal
    newMail.Body = bodyVal
    newMail.To = toVal
    newMail.SaveSentMessageFolder = fdMail
    LVL 13

    Expert Comment

    wait, you mean manually without visual studio..? open command prompt window and type in the following

    CD C:\Program Files\Microsoft.NET\SDK\v1.x.xxxx\Bin

    VBC.exe /t:library  /out:C:\MyProjects\OutputObjectName  /r:System.dll,System.Data.dll,System.Drawing.dll,System.Web.UI.dll,Outlook.dll,stdole.dll  C:\MyProjects\InputObjectName.vb

    where "OutputObjectName" is file name afterwards and "InputObjectName.vb" is what it says it is...

    Assisted Solution

    Do you really need to use outlook or just send an email ?

    there is an email object that can send it for you and will not incur any overhead or interacting with outlook each time.

    There is a good sample from

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now