email with CDO and attachment

email with CDO and attachment

Postby Marcelo Via Giglio » 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: Select all  Expand view

#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  Expand view

   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
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: email with CDO and attachment

Postby Wanderson » Fri May 04, 2018 1:27 pm

Try to put the entire file path even though it is in the folder.
Wanderson
 
Posts: 332
Joined: Thu Nov 17, 2005 9:11 pm

Re: email with CDO and attachment SOLVED

Postby Marcelo Via Giglio » Fri May 04, 2018 1:43 pm

yes, this resolve the problem

thanks very much

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: email with CDO and attachment

Postby Marc Venken » 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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: email with CDO and attachment

Postby Enrico Maria Giordano » Mon May 07, 2018 10:33 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: email with CDO and attachment

Postby Marc Venken » 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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: email with CDO and attachment

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: email with CDO and attachment

Postby Marc Venken » 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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: email with CDO and attachment

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: email with CDO and attachment

Postby Marc Venken » Mon May 07, 2018 1: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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: email with CDO and attachment

Postby Enrico Maria Giordano » Mon May 07, 2018 1: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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: email with CDO and attachment

Postby Marc Venken » Mon May 07, 2018 1:30 pm

Also Thunderbird. Never Outlook
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: email with CDO and attachment

Postby Enrico Maria Giordano » Mon May 07, 2018 1:34 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 70 guests