c# Outlook email not sent stuck in Inbox

D

Devhead

I am trying to send email via Outlook Object 10 library. When I click Send,
the mail item closes but the email never gets delivered. when i open
Outlook, i discover that the inbox is littered with the messages that i
attempted to send. Why did theses messages not get delivered? Also, how can
i bring up a non-modal email window and still have it disposed of when user
either clicks Send or closes email message window? thanks.

Here my code:

msgTo = "(e-mail address removed)";
msgFrom = "(e-mail address removed)";

msgSubject = "Test Document Email";

msgBody = "Body of the message";

msgIncAtt = true;

SendEmail();

public static void SendEmail()

{

// Create the Outlook application

oOutlook = new Outlook.Application();

//Create the new message

oMsg = (Outlook.MailItem)oOutlook.CreateItem(Outlook.OlItemType.olMailItem);

//Set the basic properties.

oMsg.To = msgTo;

oMsg.Subject = msgSubject;

oMsg.CC = msgCC;

oMsg.Body = msgBody;

if (msgIncAtt)

{

//Add an attachment.

object sSource = FilePath;

object sDisplayName = "Test Document";

object iPosition = (int)oMsg.Body.Length + 1;

object iAttachType = (int)Outlook.OlAttachmentType.olByValue;

oAttach = oMsg.Attachments.Add(sSource,iAttachType,iPosition,sDisplayName);

}

oMsg.Save();

oMsg.Display(true);

}
 
J

Jim Vierra

I don't see a message send call. If you do it from the user interface and
the object goes out of scope before it is sent it might not get sent. I
don't see why they are ending up in the Inbox. Try commenting out the
oMsg.Save and see what you get.
 
D

Devhead

the send is performed(i thought) when i click send on the email message
window(the window is displayed modal from oMsg.Display(true);) I uncommented
out the IMsg.Save but when i went into Outlook and hit the Send/Receive
button, the message was finally sent. it should be sent automatically i
thought.
 
D

Devhead

upon closer examination, there is no mail item in inbox. however, when i
click send/receive button the message(whenever it is located) is sent.
what's going on here? puzzled........
 
D

Devhead

Some more info:

the message is not stuck in inbox, it is sent to Outbox but not delivered.
 
D

Devhead

understand the issue. no more helped for email "stuck". however, i still
need help here:

how can i bring up a non-modal email window and still have it disposed of
when user either clicks Send or closes email message window?

thanks.
 
J

Jim Vierra

I have attached the project files (zip) for a complete fixed working example
of sending a message with Outlook 11.0 (2003). It has been tested for about
30 minutes so it could still have a couple of bugs. It is the exact sample
from Microsoft with the code fixed to work correctly with the 2003 Interop
assembly. I also is a post security update version so it navigates the
issues created by that. When run it will display a filled in mail item and
let you click send. Outlook stays hidden and close when the item is sent.

It's a basic demo and doesn't account for an active copy of Outlook. It
nees to test the Itemsend event to see what item is being sent and only kill
the object on the correct item. Startup doesn't wait for logon and it
should. Other checks may be in order depending on what you want to do. At
least, it can send a mail item which is more than the original code could
do.

I am not sure if this is possible due to security restriction on messaging
and I haven't had time to test all of the nuances.

Ok - I can see a number of issues. First the security model is enforced.
You cannot send, quit or close anything. The user interface will always
have to be displayed to complete an action.

see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/ol03csharp.asp

C# will be good for building add-ins. and the model will allow a certain
amount of external programming access with the users permission.

If I create an item with Outlook closed and automate it fully and save the
item from the user interface I get the new mailitem sent correctly.
 
J

Jim Vierra

I forgot to post the code so here it is.

Devhead - it should answer your questions.
 
D

Devhead

spoke too soon. the email is still in Outbox. it is delivered when i have
outlook open but is stored in Outbox when Outlook is closed and I send the
email via .NET client.

after the sendemail(), i run:

CloseOutlookApp();

i think i might not be given adequate time before my attachment (> 500kb) to
send before i dispose of outlook. any ideas? as you can tell, i just started
coding .NET 3 weeks ago but i have a delphi background. thx 2 all.
private static void CloseOutlookApp()

{

Marshal.ReleaseComObject (oAttach);

oAttach = null;

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

oMsg = null;

oOutlook.Quit();

Marshal.ReleaseComObject (oOutlook);

oOutlook = null;

GC.Collect();

GC.WaitForPendingFinalizers();

}
 
J

Jim Vierra

DEvhead - stopposting to multiple groups please. It's very annoying. We wil continue in the sdks forum please.

When replying next time delete all of the newsgroups from the to field except for the sdk forum

The moderator should delete these thread from all but the sdk forum. nntp:microsoft.public.office.developer.office.sdks
 
J

Jim Vierra

You cannot close the app immediately or it will abort the send. Outlook
also needs to be configured for immediate send which is not necessarily the
default.
 
D

Devhead

it seems the mail message is "stuck" in the Outbox and isn't delivered :(

am i still missing something here? i've been trying to cut this tree down but keep hitting the "knot in the wood".

my code is below.

devhead
DEvhead - stopposting to multiple groups please. It's very annoying. We wil continue in the sdks forum please.

When replying next time delete all of the newsgroups from the to field except for the sdk forum

The moderator should delete these thread from all but the sdk forum. nntp:microsoft.public.office.developer.office.sdks
 
D

Devhead

i tried to send email through IE > Tools > Mail and News > New Message....

seeing the same behavior. i.e., sent to Outlook Outbox but not delivered. what's going on here? puzzled.....
it seems the mail message is "stuck" in the Outbox and isn't delivered :(

am i still missing something here? i've been trying to cut this tree down but keep hitting the "knot in the wood".

my code is below.

devhead
DEvhead - stopposting to multiple groups please. It's very annoying. We wil continue in the sdks forum please.

When replying next time delete all of the newsgroups from the to field except for the sdk forum

The moderator should delete these thread from all but the sdk forum. nntp:microsoft.public.office.developer.office.sdks
 
J

Jim Vierra

Devhead -

It seems that the latest security upgrades have block the sendin. The next time you open Outlook (after IE send) the message will be sent on the next scheduled send/receive).

--
Jim Vierra
i tried to send email through IE > Tools > Mail and News > New Message....

seeing the same behavior. i.e., sent to Outlook Outbox but not delivered. what's going on here? puzzled.....
it seems the mail message is "stuck" in the Outbox and isn't delivered :(

am i still missing something here? i've been trying to cut this tree down but keep hitting the "knot in the wood".

my code is below.

devhead
DEvhead - stopposting to multiple groups please. It's very annoying. We wil continue in the sdks forum please.

When replying next time delete all of the newsgroups from the to field except for the sdk forum

The moderator should delete these thread from all but the sdk forum. nntp:microsoft.public.office.developer.office.sdks
 
J

Jim Vierra

In the example the myMailItem.Send(); needs to be cast like this (myMailItem as Outlook._MailItem).Send();

Changing this and the application works as intended (but with security warnings)

--
Jim Vierra
Devhead -

It seems that the latest security upgrades have block the sendin. The next time you open Outlook (after IE send) the message will be sent on the next scheduled send/receive).

--
Jim Vierra
i tried to send email through IE > Tools > Mail and News > New Message....

seeing the same behavior. i.e., sent to Outlook Outbox but not delivered. what's going on here? puzzled.....
it seems the mail message is "stuck" in the Outbox and isn't delivered :(

am i still missing something here? i've been trying to cut this tree down but keep hitting the "knot in the wood".

my code is below.

devhead
DEvhead - stopposting to multiple groups please. It's very annoying. We wil continue in the sdks forum please.

When replying next time delete all of the newsgroups from the to field except for the sdk forum

The moderator should delete these thread from all but the sdk forum. nntp:microsoft.public.office.developer.office.sdks
 
D

Dude

I had the same problem with Outlook 2003 (and not in the previous versions), and finally found two solutions :

- first is to use a command line e-mailer (such as NetmailBot, but there are many more).
- second is to use "redemption" objects : redemption is a duplication of Outlook object collections that are not blocked by security issues.

Take care

In the example the myMailItem.Send(); needs to be cast like this (myMailItem as Outlook._MailItem).Send();

Changing this and the application works as intended (but with security warnings)

--
Jim Vierra
Devhead -

It seems that the latest security upgrades have block the sendin. The next time you open Outlook (after IE send) the message will be sent on the next scheduled send/receive).

--
Jim Vierra
i tried to send email through IE > Tools > Mail and News > New Message....

seeing the same behavior. i.e., sent to Outlook Outbox but not delivered. what's going on here? puzzled.....
it seems the mail message is "stuck" in the Outbox and isn't delivered :(

am i still missing something here? i've been trying to cut this tree down but keep hitting the "knot in the wood".

my code is below.

devhead
DEvhead - stopposting to multiple groups please. It's very annoying. We wil continue in the sdks forum please.

When replying next time delete all of the newsgroups from the to field except for the sdk forum

The moderator should delete these thread from all but the sdk forum. nntp:microsoft.public.office.developer.office.sdks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top