Solved

MAPISendMail giving MAPI_E_FAILURE on Outlook

Posted on 2007-04-02
4
7,935 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
4 Comments
 
LVL 32

Accepted Solution

by:
and235100 earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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 …
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: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now