Solved

MAPISendMail giving MAPI_E_FAILURE on Outlook

Posted on 2007-04-02
4
8,125 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 125 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 125 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

726 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