Page 1 of 1

email with CDO and attachment

Posted: Fri May 04, 2018 12:43 pm
by Marcelo Via Giglio
Hello,

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

Code: Select all

#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: Select all

   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

Re: email with CDO and attachment

Posted: Fri May 04, 2018 1:27 pm
by Wanderson
Try to put the entire file path even though it is in the folder.

Re: email with CDO and attachment SOLVED

Posted: Fri May 04, 2018 1:43 pm
by Marcelo Via Giglio
yes, this resolve the problem

thanks very much

Marcelo

Re: email with CDO and attachment

Posted: Mon May 07, 2018 10:10 am
by Marc Venken
Is mailing with CDO a better way than with :

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

Just Curious...

Re: email with CDO and attachment

Posted: Mon May 07, 2018 10:33 am
by Enrico Maria Giordano
MAPI is for a single mail (manual) while CDO is for a batch of mails (automatic).

EMG

Re: email with CDO and attachment

Posted: Mon May 07, 2018 11:01 am
by Marc Venken
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

Re: email with CDO and attachment

Posted: Mon May 07, 2018 11:38 am
by Enrico Maria Giordano
Marc Venken wrote:I was using MAPI in a loop ))
Yes, but you still have to confirm manually each mail sending.

EMG

Re: email with CDO and attachment

Posted: Mon May 07, 2018 12:49 pm
by Marc Venken
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.

Re: email with CDO and attachment

Posted: Mon May 07, 2018 12:53 pm
by Enrico Maria Giordano
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

Re: email with CDO and attachment

Posted: Mon May 07, 2018 1:05 pm
by Marc Venken
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)

Re: email with CDO and attachment

Posted: Mon May 07, 2018 1:19 pm
by Enrico Maria Giordano
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

Re: email with CDO and attachment

Posted: Mon May 07, 2018 1:30 pm
by Marc Venken
Also Thunderbird. Never Outlook

Re: email with CDO and attachment

Posted: Mon May 07, 2018 1:34 pm
by Enrico Maria Giordano
I'm afraid that it will not work with Outlook. Anybody can test it?

EMG