?
Solved

MAPISendMail giving MAPI_E_FAILURE on Outlook

Posted on 2007-04-02
4
Medium Priority
?
8,298 Views
Last Modified: 2012-08-13
We have a general mail interface programmed in Delphi that calls MAPISendMail. This works fine on all machines except one which consistently returns MAPI_E_FAILURE. This particular machine is running Windows XP and has Outlook 2003 as the default mail server. Other machines with the same setup run fine. If the default mail server is changed to Outlook Express then this machine also works fine. I have written a simple test program that just calls MAPISendMail as follows:

FillChar(MapiMessage,SizeOf(MapiMessage),#0);
MapiFlags:=MAPI_DIALOG or MAPI_LOGON_UI;
MapiSend(0,Application.Handle,MapiMessage,MapiFlags,0);

This gives MAPI_E_FAILURE trying to load Outlook on the above machine but loads a blank email dialog on all other machines. I've also tried MAPILogon first and the logon works but MAPISendMail still fails with the same error. Any suggestions what might be causing this problem ?
0
Comment
Question by:ashdata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Accepted Solution

by:
and235100 earned 500 total points
ID: 18835082
Could this be of any use?

http://support.microsoft.com/kb/315500
0
 
LVL 1

Assisted Solution

by:bhavesh_joshi
bhavesh_joshi earned 500 total points
ID: 18944377
Try the following, It works on Outlook as well as any other email client like Outlook express


function TfmMain.sendMail(const TargetAddr,SenderAddr,MsgSubject, MsgContent:String; Attachment, Attachname:Tstringlist; PreviewMsg : Boolean = TRUE ) : String;
type
TAttachAccessArray = array [0..0] of TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;
var
  msg       : TMapiMessage;
  mrdSender,
  mrdTarget : TMapiRecipDesc;
  liFlags   : Longint;
  I:Integer;
  Attachments: PAttachAccessArray;
  MAPIError: DWord;
  strname:String;
begin
 result := '';
 liFlags := 0;
 fillChar( msg, sizeOf( msg ), 0 );
 with msg do
 begin
      flFlags:=0;
      mrdTarget.lpszName := pChar( TargetAddr );
      mrdTarget.ulRecipClass := MAPI_TO;
      mrdTarget.lpszAddress := pChar('SMTP:'+TargetAddr );
      mrdTarget.ulReserved := 0;
      mrdTarget.ulEIDSize := 0;
      mrdTarget.lpEntryID := NIL;
      nRecipCount := 1;
      lpRecips := @mrdTarget;

      mrdSender.lpszName := pChar('');
      mrdSender.ulRecipClass := MAPI_ORIG;
      mrdSender.lpszAddress := pChar('');
      //mrdSender.lpszAddress := pChar( SenderAddr );
      mrdSender.ulReserved := 0;
     mrdSender.ulEIDSize := 0;
      mrdSender.lpEntryID := NIL;
      lpOriginator := @mrdSender;

   if MsgSubject = '' then lpszSubject := ''  else lpszSubject := pChar( MsgSubject );
   if MsgContent = '' then  lpszNoteText := 'Please see the attached file.' else lpszNoteText := pChar(MsgContent);
   if Attachment.Count > 0 then
   begin
      GetMem(Attachments, SizeOf(TMapiFileDesc) * Attachment.Count);
      for i := 0 to Attachment.Count - 1 do
      begin
        Attachments[i].ulReserved := 0;
        Attachments[i].flFlags := 0;
        Attachments[i].nPosition := ULONG($FFFFFFFF);
        Attachments[i].lpszPathName := StrNew(PChar(Attachment[i]));
        Attachments[i].lpszFileName := StrNew(PChar(ExtractFileName(Attachname[i])));
        Attachments[i].lpFileType := nil;
      end;
      msg.nFileCount := Attachment.Count;
      msg.lpFiles := @Attachments^;
    end;
    if previewMsg then liFlags := MAPI_DIALOG ;
    try
     MAPIError := mapiSendMail( 0, Application.Handle, msg, liFlags, 0 );

    case MAPIError of
          MAPI_E_AMBIGUOUS_RECIPIENT    :Result:='A recipient matched more than one of the recipients. No message was sent.';
          MAPI_E_ATTACHMENT_NOT_FOUND   :Result:='The specified attachment was not found; no message was sent.';
          MAPI_E_ATTACHMENT_OPEN_FAILURE:Result:='The specified attachment could not be opened; no message was sent.';
          MAPI_E_BAD_RECIPTYPE          :Result:='The email address seems incorrect. No message was sent.';
          MAPI_E_FAILURE                :Result:='One or more unspecified errors occurred; no message was sent.';
          MAPI_E_INSUFFICIENT_MEMORY    :Result:='There was insufficient memory to proceed. No message was sent.';
          MAPI_E_DISK_FULL              :Result:='There was insufficient memory to proceed. No message was sent.';
          MAPI_E_LOGIN_FAILURE          :Result:='There was no default logon in the mail application, and the user failed to log on successfully when the logon dialog box was displayed. No message was sent.';
          MAPI_E_TEXT_TOO_LARGE         :Result:='The text in the message was too large to sent; the message was not sent.';
          MAPI_E_TOO_MANY_FILES         :Result:='There were too many file attachments; no message was sent.';
          MAPI_E_TOO_MANY_RECIPIENTS    :Result:='There were too many recipients; no message was sent.';
          MAPI_E_UNKNOWN_RECIPIENT      :Result:='A recipient did not appear in the address list; no message was sent.';
          MAPI_E_USER_ABORT             :Result:='The user canceled the process; no message was sent.';
          MAPI_E_TYPE_NOT_SUPPORTED     :Result:='Type not supported; no message was sent.';
          MAPI_E_ACCESS_DENIED          :Result:='Access Denied. No message was sent.';

          MAPI_E_ATTACHMENT_WRITE_FAILURE   :Result:='Unable to write attachment. No message was sent.';
          MAPI_E_INVALID_EDITFIELDS         :Result:='Invalid edit field. No message was sent.';
          MAPI_E_INVALID_MESSAGE            :Result:='Message is invalid. No message was sent.';
          MAPI_E_INVALID_RECIPS             :Result:='Receipients are invalid. No message was sent.';
          MAPI_E_INVALID_SESSION            :Result:='Session error. No message was sent.';
          MAPI_E_MESSAGE_IN_USE             :Result:='Message is in use. No message was sent.';
          MAPI_E_NETWORK_FAILURE            :Result:='Network error. No message was sent.';
          MAPI_E_NO_MESSAGES                :Result:='There are no messages. No message was sent.';
          MAPI_E_NOT_SUPPORTED              :Result:='Unsupported error. No message was sent.';
          MAPI_E_TOO_MANY_SESSIONS          :Result:='Too may sessions are open. No message was sent.';
          SUCCESS_SUCCESS                   :Result:='';
     else
          Result:='Email failed with an unknown error code.';
     end;
    finally
    end;

 end;
end;
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21156551
Forced accept.

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question