FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour email with CDO and attachment
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
email with CDO and attachment
Posted: Fri May 04, 2018 12:43 PM
Hello,

I have problems when I try to add attachment to email, the follow sample work when I comment the attachment line

Code (fw): Select all Collapse
#include "fivewin.ch"

function main()
   LOCAL oEmailMsg
   LOCAL cSchema := "http://schemas.microsoft.com/cdo/configuration/"
   
      oEmailMsg  := CREATEOBJECT ( "CDO.Message" )

      WITH OBJECT oEmailMsg
     
         :From     := "email@gmail.com" 
         :To       := "email@gmail.com"
         :CC       := ""
         :BCC      := ""
         :Subject  := ALLTRIM( "ALGO" )
         :TextBody := "CUERPITO"

         :AddAttachment( ALLTRIM( "email.prg" ) ) // <------ error aqui
              
         WITH OBJECT :configuration:Fields

            :Item( cSchema + "smtpserver" ):Value       := "smtp.gmail.com" 
            :Item( cSchema + "smtpserverport" ):Value   := 465
            :Item( cSchema + "sendusing" ):Value        := 2
            :Item( cSchema + "smtpauthenticate" ):Value := .T.
            :Item( cSchema + "smtpusessl" ):Value       := .T.
            :Item( cSchema + "sendusername" ):Value     := "email@gmail.com"
            :Item( cSchema + "sendpassword" ):Value     := "somepassword"
            :Item( cSchema + "smtpconnectiontimeout"):Value := 30

            :Update()

         END WITH        

         :Send()

      END WITH

RETURN NIL


I get

Code (fw): Select all Collapse
   Time from start: 0 hours 0 mins 0 secs 
   Error occurred at: 05/04/18, 08:39:19
   Error description: Error CDO.Message/3  DISP_E_MEMBERNOTFOUND: ADDATTACHMENT


I try :attachments:add("file"), :attachment := "file" and other alternatives, but I can't get that it work, I 'm testing in win10

Some help

Regards

Marcelo
Posts: 332
Joined: Thu Nov 17, 2005 09:11 PM
Re: email with CDO and attachment
Posted: Fri May 04, 2018 01:27 PM

Try to put the entire file path even though it is in the folder.

Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: email with CDO and attachment SOLVED
Posted: Fri May 04, 2018 01:43 PM

yes, this resolve the problem

thanks very much

Marcelo

Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 10:10 AM

Is mailing with CDO a better way than with :

 DEFINE MAIL oMail ;
    SUBJECT oRsEmail:header;
    TEXT    cText;
    FILES   cFile, cFile ;
    TO      cMail

Just Curious...

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 10:33 AM

MAPI is for a single mail (manual) while CDO is for a batch of mails (automatic).

EMG

Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 11:01 AM

Thanks.

I was using MAPI in a loop ))

I will look into the sample above. Seems more parameters can be coded like with server,...

Marc

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 11:38 AM
Marc Venken wrote:I was using MAPI in a loop ))


Yes, but you still have to confirm manually each mail sending.

EMG
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 12:49 PM

Indeed. If I use the FROM USER clause, I need to corfirm them one by one.

Without the FROM USER (it uses the selected send user) than it works in the loop.

The CDO however can be set better, so I will recode my sendmail function for better performance and control.

Thanks for the info.

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 12:53 PM
Marc Venken wrote:Indeed. If I use the FROM USER clause, I need to corfirm them one by one.

Without the FROM USER (it uses the selected send user) than it works in the loop.


No, MAPI doesn't work in automatic mode anymore since years.

EMG
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 01:05 PM

Aha, Then I suppose i'm not using MAPI, sorry ))

This i Use (then there is another mail option (CDO, this one and MAPI) I will look into CDO.

if empty(cFile)
DEFINE MAIL oMail ;
SUBJECT oRsEmail:header;
TEXT cText;
TO cMail
else
DEFINE MAIL oMail ;
SUBJECT oRsEmail:header;
TEXT cText;
FILES cFile, cFile ;
TO cMail
endif

ACTIVATE MAIL oMail

For me automatic is when I loop and all mails are send. (Ok, They come into my sendbox, but they go out without my action)

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 01:19 PM

Ok, works fine for me too, after a confirm dialog that can be avoided. Great! :-)

I'm using Thunderbird. Can you test with Oulook, please?

EMG

Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 01:30 PM

Also Thunderbird. Never Outlook

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: email with CDO and attachment
Posted: Mon May 07, 2018 01:34 PM

I'm afraid that it will not work with Outlook. Anybody can test it?

EMG

Continue the discussion