🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13650

Re: Send a mail with attachment

#13650
From: David Ayre
Date: Thu, 02 Oct 2003 09:29
123 lines
4995 bytes
I have managed to build the .lib file for the mapi32.dll and the
programme compliles. I now have the problem that it returns an
error code saying that logon failed.
This is my code:-

   MapiMessage lpMessage;
   MapiRecipDesc lpSender,lpRecip;
   MapiFileDesc lpFiles;
   lpFiles.ulReserved = 0UL;
   lpFiles.lpszPathName = "c:\\mtfml";
   lpFiles.lpszFileName = "invoice.pdf";
   lpFiles.lpFileType = ".PDF";
   lpFiles.nPosition = 0;
   lpFiles.flFlags = 0;
   lpSender.ulReserved = 0UL;
   lpSender.ulRecipClass = MAPI_ORIG;
   lpSender.lpszName = "David C Ayre";
   lpSender.lpszAddress = "davidcayre@aol.com";
   lpRecip.ulReserved = 0UL;
   lpRecip.ulRecipClass = MAPI_TO;
   lpRecip.lpszName = "David C Ayre";
   lpRecip.lpszAddress = "sdspublishing@aol.com";
   memset(&lpMessage,0,sizeof(lpMessage));
   lpMessage.ulReserved = 0UL;
   lpMessage.lpszSubject = "Test Message";
   lpMessage.lpszNoteText = "This is a test message";
   lpMessage.lpszMessageType = 0;
   lpMessage.lpszDateReceived = 0;
   lpMessage.lpszConversationID = 0;
   lpMessage.lpOriginator = &lpSender;
   lpMessage.lpRecips = &lpRecip;
   lpMessage.nRecipCount = 1;
   lpMessage.nFileCount = 1;
   lpMessage.lpFiles = &lpFiles;
   lpMessage.flFlags = MAPI_LOGON_UI | MAPI_NEW_SESSION;
   ULONG ulResult = MAPISendMail(0,0,&lpMessage,MAPI_NEW_SESSION,0);
   switch(ulResult)
   {
      case SUCCESS_SUCCESS:
         ShowMessage("eMail sent");
         break;

      case MAPI_E_AMBIGUOUS_RECIPIENT:
         ShowMessage("Ambiguous Recipient");
         break;

      case MAPI_E_ATTACHMENT_NOT_FOUND:
         ShowMessage("Attachment not found");
         break;

      case MAPI_E_ATTACHMENT_OPEN_FAILURE:
         ShowMessage("Attachment open failure");
         break;

      case MAPI_E_BAD_RECIPTYPE:
         ShowMessage("Bad recip type");
         break;

      case MAPI_E_FAILURE:
         ShowMessage("Failure");
         break;

      case MAPI_E_LOGIN_FAILURE:
         ShowMessage("Login failure");
         break;

      case MAPI_E_TEXT_TOO_LARGE:
         ShowMessage("Text too large");
         break;

      case MAPI_E_UNKNOWN_RECIPIENT:
         ShowMessage("Unknown recipient");
         break;

      default:
         ShowMessage("Unknown fault");
   }

Any suggestions?

Cheers,

David

"David Ayre" <davidcayre@aol.com> wrote:
>
>Thanks Remy & Rodolfo,
>
>I think I favour the .lib file method. It is the way I normally deal with dlls. I'll give it a try anyway.
>
>Thanks again for the help.
>
>Cheers,
>
>David
>
>
>"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
>>
>>"Rodolfo Frino" <rodolfofrino@yahoo.com> wrote in message
>>news:3f79c517@newsgroups.borland.com...
>>> Not bad, but there is a  better way of doing that, have a
>>> look at my other post.
>>
>>The only difference between your suggestion and mine is that your code
>>dynamically loads the DLL at runtime whereas mine statically links to it at
>>compile-time instead.  Either way, the same DLL is being accessed at runtime
>>once the functions contained inside of the DLL are actually being called by
>>the user's code.  It is just a matter of where the function pointers are
>>coming from.  And since most modern computers have MAPI installed now
>>anyway, there is little difference between using run-time loading vs.
>>compile-time linking.  In the older days, MAPI wasn't as readily available,
>>so run-time loading was used to make sure MAPI was installed first before
>>trying to use it.  That is not so much the case anymore, unless you're
>>trying to write programs that have backwards support all the way back to the
>>earliest of the Windows 95 versions.
>>
>>
>>Gambit
>>
>>
>
Technical Details
Message-ID: <3f7beff9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f70794d@newsgroups.borland.com> <3f784a32@newsgroups.borland.com> <3f79708b@newsgroups.borland.com> <3f79860c@newsgroups.borland.com> <3f799567@newsgroups.borland.com> <3f79bd46$1@newsgroups.borland.com> <3f79c517@newsgroups.borland.com> <3f79d851@newsgroups.borland.com> <3f7a8b6d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,23d9e1242f297072
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-10-02 02:41:14 PST
From: "David Ayre" <davidcayre@aol.com>
Sender: "David Ayre" <davidcayre@aol.com>
Reply-To: "David Ayre" <davidcayre@aol.com>
Subject: Re: Send a mail with attachment
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 195.93.34.11     
References:  <3f70794d@newsgroups.borland.com> <3f784a32@newsgroups.borland.com> <3f79708b@newsgroups.borland.com> <3f79860c@newsgroups.borland.com> <3f799567@newsgroups.borland.com> <3f79bd46$1@newsgroups.borland.com> <3f79c517@newsgroups.borland.com> <3f79d851@newsgroups.borland.com> <3f7a8b6d$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <3f7beff9$1@newsgroups.borland.com>
Date: 2 Oct 2003 02:29:29 -0700
X-Trace: newsgroups.borland.com 1065086969 207.105.83.66 (2 Oct 2003 02:29:29 -0700)
Lines: 124
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail