How to to add com references manually to aspx page?

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?


Who is Participating?
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
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...
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.