Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:21:20+00:00 2026-06-13T10:21:20+00:00

C# application crashes after sending xml through outlook mail. Also it requires outlook to

  • 0

C# application crashes after sending xml through outlook mail. Also it requires outlook to be closed while sending mail.Using OUTLOOK 2010. It works fine with lower versions.

using System;
using System.Reflection;

namespace Amdocs.Infra.Controls
{
   public class OutlookWrapper
   {
     public OutlookWrapper ()
     {
       outlookType = Type.GetTypeFromProgID ("Outlook.Application", true);
       outlookObject = Activator.CreateInstance (outlookType);
       namespaceMAPI = outlookType.InvokeMember ("GetNamespace", BindingFlags.InvokeMethod, null, outlookObject, new object [] {"MAPI"});
       namespaceMAPIType = namespaceMAPI.GetType ();
       namespaceMAPIType.InvokeMember ("Logon", BindingFlags.InvokeMethod, null, namespaceMAPI, new object [] {null, null, true, false});
     }
#endregion

#region ~OutlookWrapper ()
~OutlookWrapper ()
{
  namespaceMAPIType.InvokeMember ("Logoff", BindingFlags.InvokeMethod, null, namespaceMAPI, new object [] {});
}
#endregion

#region SendMail

#region public void SendMail (bool modal, string toValue)
public void SendMail (bool modal, string toValue)
{
  SendMail (modal, toValue, String.Empty);
}
#endregion
#region public void SendMail (bool modal, string toValue, string subjectValue)
public void SendMail (bool modal, string toValue, string subjectValue)
{
  SendMail (modal, toValue, subjectValue, String.Empty);
}
#endregion
#region public void SendMail (bool modal, string toValue, string subjectValue, string bodyValue)
public void SendMail (bool modal, string toValue, string subjectValue, string bodyValue)
{
  SendMail (modal, toValue, subjectValue, bodyValue, null);
}
#endregion
#region public void SendMail (bool modal, string toValue, string subjectValue, string bodyValue, string[] attachments)
public void SendMail (bool modal, string toValue, string subjectValue, string bodyValue, string[] attachments)
{
  CreateNewMailItem (toValue, subjectValue, bodyValue, attachments);
  outlookMailItemType.InvokeMember ("Send", BindingFlags.InvokeMethod, null, outlookMailItem, new object [] {modal});
}
#endregion

#endregion

#region NewMail

#region public void NewMail ()
public void NewMail ()
{
  NewMail (true);
}
#endregion
#region public void NewMail (bool modal)
public void NewMail (bool modal)
{
  NewMail (modal, String.Empty);
}
#endregion
#region public void NewMail (bool modal, string toValue)
public void NewMail (bool modal, string toValue)
{
  NewMail (modal, toValue, String.Empty);
}
#endregion
#region public void NewMail (bool modal, string toValue, string subjectValue)
public void NewMail (bool modal, string toValue, string subjectValue)
{
  NewMail (modal, toValue, subjectValue, String.Empty);
}
#endregion
#region public void NewMail (bool modal, string toValue, string subjectValue, string bodyValue)
public void NewMail (bool modal, string toValue, string subjectValue, string bodyValue)
{
  NewMail (modal, toValue, subjectValue, bodyValue, null);
}
#endregion
#region public void NewMail (bool modal, string toValue, string subjectValue, string bodyValue, string[] attachments)
public void NewMail (bool modal, string toValue, string subjectValue, string bodyValue, string[] attachments)
{
  CreateNewMailItem (toValue, subjectValue, bodyValue, attachments);
  outlookMailItemType.InvokeMember ("Display", BindingFlags.InvokeMethod, null, outlookMailItem, new object [] {modal});
}
#endregion

#endregion

#region private void CreateNewMailItem (string toValue, string subjectValue, string bodyValue, string[] attachments)
private void CreateNewMailItem (string toValue, string subjectValue, string bodyValue, string[] attachments)
{
  outlookMailItem = outlookType.InvokeMember ("CreateItem", BindingFlags.InvokeMethod, null, outlookObject, new object [] {null});
  if (outlookMailItem == null) throw new ApplicationException (StringsManager.GetString("Cannot create outlook mail item."));

  outlookMailItemType = outlookMailItem.GetType ();
  if (outlookMailItemType == null) throw new ApplicationException (StringsManager.GetString("Cannot get outlook mail item type."));

  outlookMailItemType.InvokeMember ("To",      BindingFlags.SetProperty, null, outlookMailItem, new object [] {toValue});
  outlookMailItemType.InvokeMember ("Subject", BindingFlags.SetProperty, null, outlookMailItem, new object [] {subjectValue});
  outlookMailItemType.InvokeMember ("Body",    BindingFlags.SetProperty, null, outlookMailItem, new object [] {bodyValue});

  if (attachments != null)
  {
    object attachmentsObject = outlookMailItemType.InvokeMember ("Attachments", BindingFlags.GetProperty, null, outlookMailItem, new object [] {});
    if (attachmentsObject == null) throw new ApplicationException (StringsManager.GetString("Cannot get outlook attachments property."));

    System.Type attachmentsType = attachmentsObject.GetType ();
    if (attachmentsType == null) throw new ApplicationException (StringsManager.GetString("Cannot get outlook attachments property type."));

    int bodyLength = bodyValue.Length;

    /*
     * We do not need this since we have the original text message
     * 
    object bodyObject = outlookMailItemType.InvokeMember ("Body", BindingFlags.GetProperty, null, outlookMailItem, new object [] {});
    if (bodyObject == null) throw new ApplicationException (StringsManager.GetString("Cannot get outlook body property."));

    System.Type bodyType = bodyObject.GetType ();
    if (bodyType == null) throw new ApplicationException (StringsManager.GetString("Cannot get outlook body property type."));
    */

    foreach (string s in attachments)
      attachmentsType.InvokeMember ("Add", BindingFlags.InvokeMethod, null, attachmentsObject, new object [] {s, olByValue, ++bodyLength, s});
  }
}
#endregion

#region private members

private System.Type outlookType         = null;
private object      outlookObject       = null;
private object      namespaceMAPI       = null;
private System.Type namespaceMAPIType   = null;
object              outlookMailItem     = null;
System.Type         outlookMailItemType = null;

private const int olFolderDeleted   = 3;
private const int olFolderOutbox    = 4;
private const int olFolderSentItems = 5; 
private const int olFolderInbox     = 6; 
private const int olFolderCalendar  = 9; 
private const int olFolderContacts  = 10; 
private const int olFolderJournal   = 11; 
private const int olFolderNotes     = 12; 
private const int olFolderTasks     = 13; 
private const int olFolderDrafts    = 16; 

private const int olByValue      = 1;
private const int olByReference  = 4;
private const int olEmbeddeditem = 5;

#endregion
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:21:21+00:00Added an answer on June 13, 2026 at 10:21 am

    I found the problem…go to properties(of outlook)..compatibility…select any of the older versions My application worked with XP service pack 3 compatibilty.
    Thank god…I wadted so much time in finding error details… but finally..this simple thing troubled me for 4-5 days..guys save time by using this one as your primary investigation,if you have similar issue…good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am preparing the Mail iOS application using the MailCore framework. While composing the
My application works great in debug mode but crashes after deplying it on localhost
I am battling an issue in which my application crashes while launching. When trying
While developing an application using gwt in ecliplse crashed. Now the server is running
I have strange situation in my BroadcastReceiver which uses MediaPlayer. Application crashes after certain
If an application† crashes, I hit Debug and Visual Studio is my currently registered
I want to restart my Service automatically if the application crashes. My ideas are:
I want to get the version number of my application but the application crashes
Whenever I click the button 1 , the application crashes(force closes). I am not
I have an application running on Websphere Application Server 6.0 and it crashes nearly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.