Theos PowerBasic Museum 2017

Archive => Discussion - Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Topic started by: Elias Montoya on December 02, 2008, 02:44:17 AM

Title: Re: CDO: Collaboration Data Objects
Post by: Elias Montoya on December 02, 2008, 02:44:17 AM
 Jose, how can i use this example to programatically send an e-mail using Gmail as SMPT server?

Edited:
I think it uses exchange... So i dont think it will work.

Do you have an example to authenticate in Gmail and
send an email programatically?
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on December 02, 2008, 05:18:53 AM
 
I haven't tried myself. Here you can find a VB example: http://www.a1vbcode.com/snippet-3691.asp
Title: Re: CDO: Collaboration Data Objects
Post by: Trento Castricone on December 02, 2008, 01:49:37 PM
"CDO implements most but not all MAPI functionality, although far more than Simple MAPI"

Does CDO authenticate.

pMessage.smtpserver
pMessage.smtpport
pMessage.smtpusername
pMessage.smtppassword
etc.
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on December 02, 2008, 02:15:50 PM
 
The translation of the VB example (using my include files) will be:


#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "windows.inc"
#INCLUDE ONCE "cdosys.inc"
#INCLUDE ONCE "ado.inc"

FUNCTION PBMAIN () AS LONG

'Set iMsg = CreateObject("CDO.Message")
'Set iConf = CreateObject("CDO.Configuration")
'Set Flds = iConf.Fields

DIM iMsg AS CDO_IMessage
DIM iConf AS CDO_IConfiguration
DIM Flds AS ADOFields

iMsg = NEWCOM "CDO.Message"
iConf = NEWCOM "CDO.Configuration"
Flds = iConf.Fields

' send one copy with Google SMTP server (with autentication)
'schema = "http://schemas.microsoft.com/cdo/configuration/"
'Flds.Item(schema & "sendusing") = 2
'Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
'Flds.Item(schema & "smtpserverport") = 465
'Flds.Item(schema & "smtpauthenticate") = 1
'Flds.Item(schema & "sendusername") = "mymail@gmail.com"
'Flds.Item(schema & "sendpassword") =  "mypassword"
'Flds.Item(schema & "smtpusessl") = 1
'Flds.Update

DIM schema AS STRING
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing").Value = 2
Flds.Item(schema & "smtpserver").Value = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport").Value = 465
Flds.Item(schema & "smtpauthenticate").Value = 1
Flds.Item(schema & "sendusername").Value = "mymail@gmail.com"
Flds.Item(schema & "sendpassword").Value =  "mypassword"
Flds.Item(schema & "smtpusessl").Value = 1
Flds.Update

'With iMsg
'.To = emailaddr
'.From = "Myname <myemail@mydomain.com>"
'.Subject = "Test send with gmail account"
'.HTMLBody = message
'.Sender = "Myname"
'.Organization = "Myname"
'.ReplyTo = "myemail@mydomain.com"
'Set .Configuration = iConf
'SendEmailGmail = .Send
'End With

iMsg.To = UCODE$("mail address")
iMsg.From = UCODE$("Myname <myemail@mydomain.com>")
iMsg.Subject = UCODE$("Test send with gmail account")
iMsg.HTMLBody = UCODE$("Test send with gmail account")
iMsg.Sender = UCODE$("Myname")
iMsg.Organization = UCODE$("Myname")
iMsg.ReplyTo = UCODE$("myemail@mydomain.com")
iMsg.Configuration = iConf
iMsg.Send

'set iMsg = nothing
'set iConf = nothing
'set Flds = nothing

iMsg = NOTHING
iConf = NOTHING
Flds = NOTHING

END FUNCTION

Title: Re: CDO: Collaboration Data Objects
Post by: Elias Montoya on December 02, 2008, 10:19:51 PM
  Thanx Jose, you are very kind. I will try to convert it to PB 8, as i havent been able to get PB 9 due to Mexico's economical crisis. :). I will look for your include files to download, i hope they are available.

Thank you again! :)
Title: Re: CDO: Collaboration Data Objects
Post by: Elias Montoya on December 03, 2008, 08:24:44 PM

Couldnt find them. Do you also put these for download Jose?
or am i looking in the wrong place?
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on December 03, 2008, 08:31:02 PM
 
The include files are here:
http://www.jose.it-berater.org/smfforum/index.php?board=344.0
but are for PBWIN 9.0

There are old wrappers for CDO here:
http://www.jose.it-berater.org/smfforum/index.php?topic=360.0
and for ADO here:
http://www.jose.it-berater.org/smfforum/index.php?topic=969.0
Title: Re: CDO: Collaboration Data Objects
Post by: Elias Montoya on December 03, 2008, 09:50:26 PM
Works beautifully!

Thank you yet again Jose. :)
Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on May 05, 2009, 11:23:53 PM
Hi Jose,

This example looks like exactly what I need, but I cannot get it to work.  I am trying to use it with PBCC 4.0 (5 doesn't add anything useful to me), and I keep running into problems. 

The first is that I am not sure which inc files to use.  I trying the ones in winapi.zip.  TB_CDOEX.zip does not seem to contain a cdosys.inc file.

The winapi ones have multiple problems, at least the way I am using them.  I was able to get rid of the ONCE in the INCLUDE statements, but it still won't compile.  I get for example a

   $cdoTimeZoneIDURN = "urn:schemas:calendar:timezoneid" must be outside of sub or function

message.

Any help would be greatly appreciated.

Hank                                               
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on May 06, 2009, 12:48:03 AM
Quote
This example looks like exactly what I need, but I cannot get it to work.  I am trying to use it with PBCC 4.0 (5 doesn't add anything useful to me), and I keep running into problems.

All the code in this subforum is for PBWIN 9+ and PBCC 5+, as stated in the header [Webmaster: José Roca (PBWIN 9.0+/PBCC 5.0+)]. You can't use my include files with PBCC 4.

Note for myself: I must remember to ask for the version of the compiler that the poster is using before posting any reply.

Quote
TB_CDOEX.zip does not seem to contain a cdosys.inc file.

CDOSYS is a subset of CDOEX. Therefore, you can use TB_CDOEX to work with CDOSYS. Just don't call a method or property not available in CDOSYS. If you use TB_CDOEX, please note that they are wrappers to work with CDO in a procedural way, so you can't use a compound syntax such Flds.Item(schema & "sendusing").Value, but you have to do it step by step, which will be difficult if you don't have expertise with low-level COM. You will also need TB_ADO28.

If you are going to work with COM, please make yourself a favor an update the compiler.
Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on May 12, 2009, 07:30:40 PM
Hi José,

Thanks for the reply.  Since I will need to upgrade PBCC to use CDO, I will wait until I get final project approval from my client.  I may have more questions then.

Best regards,
Hank
Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on July 06, 2009, 08:46:22 PM
Hi José,

Well, I now need to move ahead with the project.  I've gotten PBCC5 for that purpose.

I tried using the sample code you show above, along with your .inc file collection (v.1.13).  When I try to compile the example I get:

   Error 468 in c:]pbcc5\winapi\winapi.inc (167:041):  Duplicate Equate
   Line 167:  %LOGON_ZERO_PASSWORD_BUFFER = &H80000000

What should I do differently?

Thanks again for your help.

Best regards,
Hank
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on July 06, 2009, 08:58:03 PM
As stated in the Windows Headers post...

Unzip the attached file to a folder of your choice and replace the PB Include path in the PB Ide or the editor that you are using to that folder instead of C:\PBWin90\WinApi.

I guess that you don't have removed the path to the include files that come with the compiler.
Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on July 07, 2009, 12:54:42 AM
Hi José,

Thank you very much for the quick response.  Sorry I did not see that note.

Now I the sample will compile, but I cannot seem to get it to actually send mail.  I've substituted my accounts (tried 2), but I do not get anything.   

This will be part of a cgi application, but for now I just ran the exe from the command prompt.  The program takes almost 20 seconds to run, but no mail arrives.

How can I troubleshoot this?  Is there some code I could add as a diagnostic?

Best regards,
Hank
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on July 07, 2009, 02:24:04 AM
I have tried it using my gmail account and it works.

Quote
How can I troubleshoot this?  Is there some code I could add as a diagnostic?

Put the code between a TRY/END TRY block.


TRY
....
...
CATCH
  ? HEX$(OBJRESULT)
END TRY

Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on July 07, 2009, 07:16:12 PM
Hi José,

I followed your suggestion and get

80040213

at the command prompt.  But I do not know what that means.

Best regards,
Hank
Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on July 07, 2009, 07:25:07 PM
Hi José,

Additional info:

I moved the TRY to isolate the problem, and it occurs at the iMsg.Send step.

Best regards,
Hank
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on July 07, 2009, 07:56:10 PM
You can find the CDO error codes in the file CDOEXERR.INC and in this Microsoft page: http://msdn.microsoft.com/en-us/library/ms526287(EXCHG.10).aspx

Error 80040213 (%CDO_E_FAILED_TO_CONNECT):
The transport failed to connect to the server.
Title: Re: CDO: Collaboration Data Objects
Post by: Hank Zucker on July 07, 2009, 09:51:12 PM
Hi José,

Thanks for the additional info.

I tried using my gmail account and now get:

  Error 80040211 (CDO_E_SMTP_SEND_FAILED)
  "The message could not be sent to the SMTP server. The transport error code was %2. The server response was %1"

How do I find out what %2 and %1 are?

Can you please give me the exact code you used when successfully using your gmail account, with only your account name and password changed?  I tried using your earlier example code when I got the above error.

Thanks again!

Hank
Title: Re: CDO: Collaboration Data Objects
Post by: José Roca on July 07, 2009, 10:41:36 PM
Quote
How do I find out what %2 and %1 are?

If you use my wrapper function OleGetErrorInfo, as in the example below, it will display a full description as returned by the provider.

Quote
Can you please give me the exact code you used when successfully using your gmail account, with only your account name and password changed?  I tried using your earlier example code when I got the above error.

Here is the code:


#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "windows.inc"
#INCLUDE ONCE "cdosys.inc"
#INCLUDE ONCE "ado.inc"
#INCLUDE ONCE "ole2utils.inc"

FUNCTION PBMAIN () AS LONG

   DIM iMsg AS CDO_IMessage
   DIM iConf AS CDO_IConfiguration
   DIM Flds AS ADOFields

   iMsg = NEWCOM "CDO.Message"
   iConf = NEWCOM "CDO.Configuration"

   TRY

      Flds = iConf.Fields
      DIM schema AS STRING
      schema = "http://schemas.microsoft.com/cdo/configuration/"
      Flds.Item(schema & "sendusing").Value = 2
      Flds.Item(schema & "smtpserver").Value = "smtp.gmail.com"
      Flds.Item(schema & "smtpserverport").Value = 465
      Flds.Item(schema & "smtpauthenticate").Value = 1
      Flds.Item(schema & "sendusername").Value = "mymail@gmail.com"
      Flds.Item(schema & "sendpassword").Value =  "mypassword"
      Flds.Item(schema & "smtpusessl").Value = 1
      Flds.Update

      iMsg.To = UCODE$("my first email address")
      iMsg.From = UCODE$("José Roca <my 2nd email address>")
      iMsg.Subject = UCODE$("Test send with gmail account")
      iMsg.HTMLBody = UCODE$("Test send with gmail account")
      iMsg.Sender = UCODE$("José Roca")
      iMsg.Organization = UCODE$("José Roca")
      iMsg.ReplyTo = UCODE$("José Roca <my 2nd email address>")
      iMsg.Configuration = iConf
      iMsg.Send
      ? "Message sent successfully"
   CATCH
      ? OleGetErrorInfo(OBJRESULT)
   END TRY

   iMsg = NOTHING
   iConf = NOTHING
   Flds = NOTHING

END FUNCTION