Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
Error Sending email with Outlook
timmytux
Mar 4 2004 11:00 PM
1.6k
Reply
I'm trying to send email with Outlook. I've read the article "Sending Emails Through Outlook using C# and VB.NET" but when I try to get the Outlook.Application I get an error when I try to run it. //Error An unhandled exception of type 'System.InvalidCastException' occurred in OutlookTest.exe Additional information: QueryInterface for interface Outlook._Application failed. Here's what I do: //globals private Outlook.Application objApplication; private Outlook.NameSpace objNameSpace; //in a function objApplication = new Outlook.Application(); objNameSpace = objApplication.GetNamespace("MAPI"); objNameSpace.Logon(null,null,true,true); Outlook.MailItem objMailItem = (Outlook.MailItem)objApplication.CreateItemOutlook.OlItemType.olMailItem); objMailItem.To = "
[email protected]
"; objMailItem.Subject = "Test"; objMailItem.Body = "as dfkasjf a;sdfj ;alsdjf ;sadf"; objMailItem.Send(); I've also tried to do the same in VB but I get the same error. I'm using Visual Studio .Net 2003 with the Microsoft Outlook 9.0 Library. Does anyone have any idea of how to fix this?
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Activator.CreateInstance question
Word Documents