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 9018017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:24:50+00:00 2026-06-16T04:24:50+00:00

I am writing a C# program that makes use of MAPI. I know I

  • 0

I am writing a C# program that makes use of MAPI. I know I should use a different language for this, but I was told to use .NET. I have the application running, but I am having a couple of problems logging in.

I can log in just fine using the current user account, but when I try to log in to a dedicated account, the mail is still sent from the current user account. My login code follows:

    private bool Logon()
    {
        if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
        {
            error = MAPILogon(WinHandle, null, null, 0, 0, ref session);
            Logging.Log("Logged in using credentials for the current user.");
        }
        else
            error = MAPILogon(WinHandle, username, password, 0, 0, ref session);

        if (error != 0)
            error = MAPILogon(WinHandle, null, null, MapiLogonUI, 0, ref session);

        return error == 0;
    }

    [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
    private static extern int MAPILogon(IntPtr hwnd, string profileName, string password, 
        int flag, int rsv, ref IntPtr session);

    [DllImport("MAPI32.DLL")]
    private static extern int MAPISendMail(IntPtr session, IntPtr hwnd, MapiMessage message, int flag, int rsv);

I have added a null terminator to the username and password (“\0”) so it seems like I should be able to log in as a different user.

I tried closing my Outlook and running the application and it said that it sent the message correctly, but froze on closing. Outlook would no longer open, and eventually I rebooted my computer. Does Outlook have to be open to use MAPI controls?

Finally, when the message is sent, I get a confirmation that “A program is trying to send an e-mail message on your behalf.” Since this app may be sending several messages a day, I don’t want the user to have to keep pressing Allow. Is there a way to suppress this message programatically or as an Outlook or Exchange Server configuration?

My dev environment is Windows 7 and Outlook 2010, but this needs to work in all environments. Sorry for having so many questions; I appreciate any insights people may have.

=== REVISED —

The first part of my question has been answered. MAPI is logging in to a profile. However, I still wonder if anyone knows how to repress the access warning message, and to get Simple MAPI to log in to an account other than the one the user is logged in to. I need to do this because all email from any station will be sent from a single dedicated account.

I would be happy to use extended MAPI if I could find more detailed information on how to use it. I found some information and even a sample program, but it gives me an error saying that “Either there is no default mail client or the current mail client cannot fulfill the messaging request”. I tried changing the processor the application is built for, but the message persisted. Since my simple MAPI application does not have this error, I know I have a default email client.

Again, thank you for any assistance.

  • 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-16T04:24:51+00:00Added an answer on June 16, 2026 at 4:24 am

    I had to switch over to using Extended MAPI, and was able to resolve both of these issues.

    Thank you, Dimitry, for your help both on this site and here.

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

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I'm writing a simple program that makes multiple connections to different servers for status
I'm writing a small JavaScript program that makes web calls to pull up weather
I am writing a program that sets up a file path that I use
I'm writing a program in Python that needs to use a site's advanced search
I'm writing an application that makes use of a tree structure, so of course
I am writing a fairly complex application that makes heavy use of STL containers.
I'm writing a java program and, before I call a method that makes heavy
I am writing a numerical program that should be somewhat fast, and is also
I'm writing a program that uses regular expressions to make comparisons against the entire

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.