Thread: Outlook
View Single Post
Old Oct 25th, 2007, 8:36 PM   #1
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
Outlook

I have a class library that is supposed to send email from outlook ... i have added a reference to the Microsoft.officecore (something like that) 12 and outlook object library 12 (i have office 2007)...im calling the DLL from a C# class in an ASP.Net application

The code fails here:
msg = OutlookApp.CreateItem(OlItemType.olMailItem) 'Mail item

Code:

Imports Microsoft.Office.Interop.Outlook

Public Class Email_vb

    Public Sub sendEmail(ByVal recipient As String, ByVal subject As String, ByVal message As String)

        Dim OutlookApp As New Application 'application

        Dim msg As _MailItem
        msg = OutlookApp.CreateItem(OlItemType.olMailItem) 'Mail item  

        Dim oNameSpace As Microsoft.Office.Interop.Outlook.NameSpace
        oNameSpace = OutlookApp.GetNamespace("MAPI")

        msg.To = recipient
        msg.Subject = subject
        msg.Body = message

        msg.Send()
    End Sub

End Class

Exception Details:


System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2147467259
Message="The operation failed."
Source="Microsoft Office Outlook"
StackTrace:
at Microsoft.Office.Interop.Outlook.ApplicationClass.CreateItem(OlItemType ItemType)
at sendMail.Email_vb.sendEmail(String recipient, String subject, String message) in E:\Documents and Settings\Paul\My Documents\Visual Studio 2005\Projects\sendMail\sendMail\Class1.vb:line 10
at Capstone.Email.sendEmail(String recipientEmail, String message, String subject) in F:\capstone_vs_project\Capstone\Capstone\Email.cs:line 23
at Capstone.BestOffer.alertSeller(String sellersName, String sellersEmail) in F:\capstone_vs_project\Capstone\Capstone\BestOffer.cs:line 216
at Capstone.BestOffer.contactSeller() in F:\capstone_vs_project\Capstone\Capstone\BestOffer.cs:line 186
at Capstone.BestOffer.addOffer(Double offerPrice) in F:\capstone_vs_project\Capstone\Capstone\BestOffer.cs:line 80
at Capstone.preview.submitBestOffer_Click(Object sender, EventArgs e) in F:\capstone_vs_project\Capstone\Capstone\preview.aspx.cs:line 280
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
paulchwd is offline   Reply With Quote