Outlook 2007 Will Not Send Mail From C# Application

  • Thread starter Thread starter Dale Franks
  • Start date Start date
D

Dale Franks

I have a C# Windows Forms application that I am developing. I am running
into a problem sending mail via Outlook 2007. The application is being
developed in VS2008. I work in a DoD (Navy) environment, where I have no
control over the security settings for Outlook. The code is very simple:

Outlook.Application oApp = new Outlook.Application();
Outlook._NameSpace oNameSpace = oApp.GetNamespace("MAPI");
Outlook.MAPIFolder oOutboxFolder =
oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
oNameSpace.Logon(null, null, false, false);
Outlook._MailItem oMailItem =
(Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = "(e-mail address removed)";
oMailItem.Subject = cboSubject.Text;
oMailItem.Body = txtMessage.Text;
oMailItem.Send();

In the application I am developing, the email DOES get sent through Outlook
2003, after the user approves the mail on the security dialog box. In 2007,
however, the Send() function results in the error:

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

In the Outlook 2007 Trust Center, the Programmatic Access security setting
is set to "Warn me about suspicious activity when my antivirus software is
inactive or out of date (recommended)", which, although I cannot change it in
the Outlook interface, seems to me to be the appropriate level of security.

I really don't care if the security dialog box appears or not. It does
appear in Outlook 2003, and the user can approve the message. That's fine.

What I don't understand is why Office 2007 refuses to either send the email,
or provide a security dialog box for the user to approve it. I can save the
email. I can move it into the Outbox, or anywhere else. I can display the
email, and have the user manually click the send button. But I can't
actually send the email.

Since the rest of the organization is scheduled to upgrade to Office 2007 in
the near future, this is a matter of some pressing interest for me.

Any suggestions?
 
What does Tools | Trust Center tell you about the status of your anti-virus
application?

Have you tried adding a Namespace.Logon statement? That may be necessary if
Outlook isn't already running.

I've also seen people report good results from displaying the message before
adding recipients and sending.
 
My anti-virus software is up to date, according to the trust center. I did
add the line to display the message prior to adding the recipient addresses
and body text. It did display, and was correctly contstructed. The Send()
function still resulkted in the same error. I can do everything imaginable
to the message...except send it.

Although after the message displays, I can hit the send button on the
displayed message form, which sends the message promptly. It just won't send
programmatically.

The code already has the Namespace.Logon() command incorporated.
 
Namespace.Logon should be invoked before any statements that use the
instantiated Namespace object. Also, if Outlook isn't already running, you
may need to prompt the user to choose a mail profile.

The only other thing I can think to try is calling Recipients.ResolveAll
before sending.

BTW, is there a particular reason why you're using Outlook and not
System.Net.Mail?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
BTW, is there a particular reason why you're using Outlook and not
System.Net.Mail?

Yeah. As I mentioned, I'm working in the US Navy NMCI environment. I'm not
allowed to touch an SMTP server. And, even if I could, the SMTP ports are
blocked anyway.
 
Dale,

I have the same problem. If have resolved please suggest your solution that
fixed your problem.

My problem:
When I send the Email programmatically (C#) through Outlook 2007, it throws
Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
error and did not send the mail.

As when OUTLOOK 2007 process is started in the background, the same
application sends successfully the email.

The same application sends the email on another machine where OutLook 2003
is installed, without the outlook 2003 process started in the background.

I appreciate your solution.

Thanks,
SAM
 
Dale

I found a soultion for my problem.

For Outlook 2007, the code needs Outlook.Inpector object.

Outlook.Application oApp = null;
Outlook.MailItem oMsg = null;
Outlook.Inspector oAddSig = null;

oApp = new Outlook.Application();
oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oAddSig = oMsg.GetInspector;

After adding Inspector object the code sends email through Outlook 2007.
That is the solution to my problem.

With Outlook 2003, the code does not need this Inspector object. Without the
Inspector object, the Outlook 2003 sends email.

THX
SAM
 
Sam,

I have a similar problem with my VB5 program using MAPI trying to send Email
thru Outlook 2000. I have an unanswered post below but wondered if you could
help.

I have a VB5 pgm that uses MAPI to send emails to customers. Everything
works fine when "Outlook Express" is installed on my XP computer. When I
replaced Outlook Express with "Outlook 2002", it appears that my pgm sends
emails out just fine, but when I click Outlook I get an error message "System
Administrator: None of your e-mail accounts could send to this recipient."

What is wrong and how can I fix this?

Dennis Rose
 
Sam, thanks a lot, the Inspector object creation fixed it for me! Now it's sending emails left and right ;-)

SAM said:
Dale

I found a soultion for my problem.

For Outlook 2007, the code needs Outlook.Inpector object.

Outlook.Application oApp = null;
Outlook.MailItem oMsg = null;
Outlook.Inspector oAddSig = null;

oApp = new Outlook.Application();
oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oAddSig = oMsg.GetInspector;

After adding Inspector object the code sends email through Outlook 2007.
That is the solution to my problem.

With Outlook 2003, the code does not need this Inspector object. Without the
Inspector object, the Outlook 2003 sends email.

THX
SAM



"SAM" wrote:

> Dale,
>
> I have the same problem. If have resolved please suggest your solution that
> fixed your problem.
>
> My problem:
> When I send the Email programmatically (C#) through Outlook 2007, it throws
> Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
> error and did not send the mail.
>
> As when OUTLOOK 2007 process is started in the background, the same
> application sends successfully the email.
>
> The same application sends the email on another machine where OutLook 2003
> is installed, without the outlook 2003 process started in the background.
>
> I appreciate your solution.
>
> Thanks,
> SAM
>
>
> "Dale Franks" wrote:
>
> > I have a C# Windows Forms application that I am developing. I am running
> > into a problem sending mail via Outlook 2007. The application is being
> > developed in VS2008. I work in a DoD (Navy) environment, where I have no
> > control over the security settings for Outlook. The code is very simple:
> >
> > Outlook.Application oApp = new Outlook.Application();
> > Outlook._NameSpace oNameSpace = oApp.GetNamespace("MAPI");
> > Outlook.MAPIFolder oOutboxFolder =
> > oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
> > oNameSpace.Logon(null, null, false, false);
> > Outlook._MailItem oMailItem =
> > (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> > oMailItem.To = "(e-mail address removed)";
> > oMailItem.Subject = cboSubject.Text;
> > oMailItem.Body = txtMessage.Text;
> > oMailItem.Send();
> >
> > In the application I am developing, the email DOES get sent through Outlook
> > 2003, after the user approves the mail on the security dialog box. In 2007,
> > however, the Send() function results in the error:
> >
> > Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
> >
> > In the Outlook 2007 Trust Center, the Programmatic Access security setting
> > is set to "Warn me about suspicious activity when my antivirus software is
> > inactive or out of date (recommended)", which, although I cannot change it in
> > the Outlook interface, seems to me to be the appropriate level of security.
> >
> > I really don't care if the security dialog box appears or not. It does
> > appear in Outlook 2003, and the user can approve the message. That's fine.
> >
> > What I don't understand is why Office 2007 refuses to either send the email,
> > or provide a security dialog box for the user to approve it. I can save the
> > email. I can move it into the Outbox, or anywhere else. I can display the
> > email, and have the user manually click the send button. But I can't
> > actually send the email.
> >
> > Since the rest of the organization is scheduled to upgrade to Office 2007 in
> > the near future, this is a matter of some pressing interest for me.
> >
> > Any suggestions?
 
Hi SAM,

I have been facing same problem with outlook 2010.

I am sending mail using OUTLOOK in my application. When i click on send button, dialog box appears asking user to allow or deny application to send mail.
If i allow then email will be sent successfully but if i deny then i am getting this error 'Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))'.

What is possible way to send mail without asking user for approval.

Thanks,
Bhargav
 
Back
Top