• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

Re: CDO: Collaboration Data Objects

Started by Elias Montoya, December 02, 2008, 02:44:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Elias Montoya

 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?

José Roca

#1
 
I haven't tried myself. Here you can find a VB example: http://www.a1vbcode.com/snippet-3691.asp

Trento Castricone

"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.

José Roca

 
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


Elias Montoya

  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! :)

Elias Montoya


Couldnt find them. Do you also put these for download Jose?
or am i looking in the wrong place?


Elias Montoya

Works beautifully!

Thank you yet again Jose. :)

Hank Zucker

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                                               

José Roca

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.

Hank Zucker

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

Hank Zucker

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

José Roca

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.

Hank Zucker

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

José Roca

#14
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