Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MAPISendMail giving MAPI_E_FAILURE on Outlook

Posted on 2007-04-02
4
Medium Priority
?
8,383 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

610 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