473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

c# Error when trying to send email

i need to present user with an Outlook mail item. the following code is a
modication to the code found
here(http://support.microsoft.com/?kbid=819398). However, when the line is
question is run(Outlook.MailItemClass mItem =
(Outlook.MailItemClass)oDoc.MailEnvelope.Item;), it generated an exception
of type System.ExecuteOnEngineException with the following message:

"Object reference not set to an instance of an object"

private static Word._Application oWord = null;

public static void SendEmail(ref Word._Application oWord)

{

object oDocType = Word.WdNewDocumentType.wdNewEmailMessage;

oDoc = oWord.Documents.Add(

ref oMissing,

ref oMissing,

ref oDocType,

ref oFalse);

Outlook.MailItemClass mItem = (Outlook.MailItemClass)oDoc.MailEnvelope.Item;

mItem.To = "so******@hotmail.com";

mItem.BCC = "none";

mItem.CC = "none";

mItem.Subject = "Test message";

mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

mItem.HTMLBody = "something going on here";

mItem.ItemEvents_Event_Close += new
Outlook.ItemEvents_CloseEventHandler(oWord_Close);

oWord.Visible = true;

// Loop until there are no more references to release.

while (Marshal.ReleaseComObject(mItem) > 0);

mItem = null;

// Invoke the .NET garbage collector.

GC.Collect();

GC.WaitForPendingFinalizers();

}

// Close the Word application after the message has been sent.

private static void oWord_Close(ref bool e)

{

CloseWordApp(ref oWord);

}
Nov 16 '05 #1
4 4455
Are you wanting to send e-mail or is this just the beginning, and you plan
to do more with the Outlook object model? If you are just sending e-mail,
just use SMTP! It's a lot easier to set up and use, and you won't need to
mess with Outlook to do it. Nothing wrong with outlook. It's an excellent
tool. However, if you just want to send a little e-mail, it's often
overkill.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Devhead" <de******@bellsouth.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
i need to present user with an Outlook mail item. the following code is a
modication to the code found
here(http://support.microsoft.com/?kbid=819398). However, when the line is
question is run(Outlook.MailItemClass mItem =
(Outlook.MailItemClass)oDoc.MailEnvelope.Item;), it generated an exception
of type System.ExecuteOnEngineException with the following message:

"Object reference not set to an instance of an object"

private static Word._Application oWord = null;

public static void SendEmail(ref Word._Application oWord)

{

object oDocType = Word.WdNewDocumentType.wdNewEmailMessage;

oDoc = oWord.Documents.Add(

ref oMissing,

ref oMissing,

ref oDocType,

ref oFalse);

Outlook.MailItemClass mItem = (Outlook.MailItemClass)oDoc.MailEnvelope.Item;
mItem.To = "so******@hotmail.com";

mItem.BCC = "none";

mItem.CC = "none";

mItem.Subject = "Test message";

mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

mItem.HTMLBody = "something going on here";

mItem.ItemEvents_Event_Close += new
Outlook.ItemEvents_CloseEventHandler(oWord_Close);

oWord.Visible = true;

// Loop until there are no more references to release.

while (Marshal.ReleaseComObject(mItem) > 0);

mItem = null;

// Invoke the .NET garbage collector.

GC.Collect();

GC.WaitForPendingFinalizers();

}

// Close the Word application after the message has been sent.

private static void oWord_Close(ref bool e)

{

CloseWordApp(ref oWord);

}

Nov 16 '05 #2
need to present Outlook user interface mainly to have a way to retrieve
contact list so user can select where the email is going.

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:4N********************@comcast.com...
Are you wanting to send e-mail or is this just the beginning, and you plan
to do more with the Outlook object model? If you are just sending e-mail,
just use SMTP! It's a lot easier to set up and use, and you won't need to
mess with Outlook to do it. Nothing wrong with outlook. It's an excellent
tool. However, if you just want to send a little e-mail, it's often
overkill.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Devhead" <de******@bellsouth.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
i need to present user with an Outlook mail item. the following code is a
modication to the code found
here(http://support.microsoft.com/?kbid=819398). However, when the line
is
question is run(Outlook.MailItemClass mItem =
(Outlook.MailItemClass)oDoc.MailEnvelope.Item;), it generated an
exception
of type System.ExecuteOnEngineException with the following message:

"Object reference not set to an instance of an object"

private static Word._Application oWord = null;

public static void SendEmail(ref Word._Application oWord)

{

object oDocType = Word.WdNewDocumentType.wdNewEmailMessage;

oDoc = oWord.Documents.Add(

ref oMissing,

ref oMissing,

ref oDocType,

ref oFalse);

Outlook.MailItemClass mItem =

(Outlook.MailItemClass)oDoc.MailEnvelope.Item;

mItem.To = "so******@hotmail.com";

mItem.BCC = "none";

mItem.CC = "none";

mItem.Subject = "Test message";

mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

mItem.HTMLBody = "something going on here";

mItem.ItemEvents_Event_Close += new
Outlook.ItemEvents_CloseEventHandler(oWord_Close);

oWord.Visible = true;

// Loop until there are no more references to release.

while (Marshal.ReleaseComObject(mItem) > 0);

mItem = null;

// Invoke the .NET garbage collector.

GC.Collect();

GC.WaitForPendingFinalizers();

}

// Close the Word application after the message has been sent.

private static void oWord_Close(ref bool e)

{

CloseWordApp(ref oWord);

}


Nov 16 '05 #3
Are you sure that the error is on the line

Outlook.MailItemClass mItem =
(Outlook.MailItemClass)oDoc.MailEnvelope.Item;

or is that just the line that is highlighted when the debugger signals
the error? Remember that for method calls, the debugger often indicates
the "current line" as being the line _after_ the call that is raising
the exception. (This has to do with the execution stack... the way that
compiled code runs inside the machine.)

If this is the case, then the problem may instead be the line,

oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oDocType,
ref oFalse);

which would make more sense, because I don't see you initializing
oMissing, oDocType, or oFalse anywhere. Could one of these be null?
These are "ref" arguments, not "out" arguments, so
oWord.Documents.Add() is expecting them to be set to something, and may
change them on return.

Nov 16 '05 #4
Nick, if you would be so kind, I have the same problem in my
application. All of the mail interfaces I saw in .NET, such as SMTP,
seemed designed to send an e-mail "silently" in the background with no
intervention from the user. I needed to show a standard "send mail"
dialog, with access to the address book and an option to set the
subject or type more into the message. In the end I resorted to
invoking Outlook.

Am I correct that SMTP is just for create-and-send behind the scenes,
or did I misunderstand the documentation?

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hi, I know i shouldn't work on php forms when i'm going on 30 hours of no sleep, but i did anyway. I'm trying to get the below to work, and i keep getting a parse error line 74, an unexpected ','...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
7
by: news | last post by:
Recently our mail from our e-commerce site has been rejected by AOL due to an IP block because someone was using our PHP scripts to send spam. Well, I got that fixed. But our legitimate...
4
by: MadeOfRose | last post by:
Hi all i was using cdo object for sending email to a customers. when use win2000 server or windows xp my script works correctly. but not on win2003 server r2. Different thing on my script is...
5
by: Jay | last post by:
error '80040211' /register.asp, line 71 I receive this error when i attempt to send an email. My code is as follows:
16
by: Ed Bitzer | last post by:
Trying to send groups of email with program using System.Net.Mail. I do not clear MailMessage but repeatedly loop changing only the Bcc entries. Works fine if all addresses are valid. As a simple...
3
by: Lance Wynn | last post by:
Hello, I am receiving this error when trying to instantiate a webservice component. I have 2 development machines, both are XP sp2 with VS 2008 installed. On one machine, the code works fine. On...
4
by: gurufordy | last post by:
Hello. Trying to use the ASP.net user functionality but it keeps failing on me. I have created a login and registration page for my site. When you fill in the registration form it should send a...
10
by: surferj | last post by:
I am beginning to receive an error message when trying to execute the .Send command when using the CDO.Configuration and CDO.Message in a W2k3 server environment on WXP machines and IE6. Below is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.