email with CDO and attachment

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

email with CDO and attachment

Post 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
Wanderson
Posts: 332
Joined: Thu Nov 17, 2005 9:11 pm

Re: email with CDO and attachment

Post by Wanderson »

Try to put the entire file path even though it is in the folder.
Marcelo Via Giglio
Posts: 1033
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: email with CDO and attachment SOLVED

Post by Marcelo Via Giglio »

yes, this resolve the problem

thanks very much

Marcelo
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: email with CDO and attachment

Post 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...
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: email with CDO and attachment

Post by Enrico Maria Giordano »

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

EMG
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: email with CDO and attachment

Post 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
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: email with CDO and attachment

Post 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
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: email with CDO and attachment

Post 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.
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: email with CDO and attachment

Post 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
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: email with CDO and attachment

Post 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)
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: email with CDO and attachment

Post 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
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: email with CDO and attachment

Post by Marc Venken »

Also Thunderbird. Never Outlook
Marc Venken
Using: FWH 20.08 with Harbour
Post Reply