Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cdo sample
Message
 
To
28/10/2004 03:56:34
General information
Forum:
Visual FoxPro
Category:
Internet applications
Title:
Miscellaneous
Thread ID:
00955172
Message ID:
00955733
Views:
16
>Hello,
>I need a vfp sample code that can send a mail with cdo.
>But i want to set the smtpserver, username, password setting self.
>I dont want to use the settings from outlook or outlook express.
>Thanks.

I'm not a big fan of CDO because of installation and configuration issues for client installations. But here's some code that works with CDO:
* Sends mail via SMTP 
FUNCTION CDOMail
LPARAMETERS lcMailServer, lcSenderEmail, lcRecipient, lcSubject, lcMessage,lcUsername,lcPassword

LOCAL iMsg as CDO.Message
iMsg = CreateObject("CDO.Message")

LOCAL iConf as CDO.Configuration
iConf = CreateObject("CDO.Configuration")

Flds = iConf.Fields

Flds.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendUsingMethod")=2   
Flds.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendUsingMethod/cdoSMTPServer")= lcMailServer
Flds.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendUsingMethod/cdoSMTPServerPort")=25

IF !EMPTY(lcUserName)
   Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")=lcPassword
   Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")=lcUsername
ENDIF

Flds.Item("urn:schemas:mailheader:content-type")="text/html"

Flds.Update

With iMsg
     .Configuration = iConf
     .To          = lcRecipient
     .From        = lcSenderEmail
     .Sender      = lcSenderEmail
     .Subject     = lcSubject
     .TextBody    = lcMessage

     *iBp =  .AddAttachment("d:\temp\home.htm")
     *iBp.ContentMediaType="text/html"
      
     TRY 
        .Send()
     CATCH TO loException
         lcError = loException.aErrors[3]     
         IF ISNULL(lcError) OR lcError = ""
            lcError = MESSAGE()
         ENDIF
     ENDTRY
ENDWITH

RETURN ""
A more robust and machine configuration independent way to do this is to use a raw SMTP component.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform