(Updated: 2008.02.16 06:46:10 PM)
| |
Recently while reading an article on ASP I discovered an extremely easy way to create emails from Fox. If you are like me you have tried any number of methods to do this, like trying to talk directly to the ISP, automating MS Outlook, or using a third party tool. I had been using a tool that comes in the IPStuff.vcx of the
West - Wind connection tool kit, which has worked wonderfully for me for quite some time. However, I have found this new method to be much easier and it will allow some more advanced features.
You will need to have Windows 2000 and MS Outlook Express for this to work, although I think you might be able to use a substitute for outlook express.
Microsoft has included a new (well new to me) COM object that makes sending an email extremely simple.
Here is the short version:
oMSG = createobject("CDO.Message")
** DO NOT FORGET TO CHANGE! You would not believe how many of theses I get! :)
oMSG.To = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.From = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.Subject = "Hello Email"
oMSG.TextBody = "This is an easy way to create an email"
oMSG.Send()
I had some problems with this method at first. The CDO.Message uses the computers default email settings. Namely Outlook express. So you need to have a default email account setup first.
Here are some other features of the CDO.Message:
oMSG = createobject("CDO.Message")
** DO NOT FORGET TO CHANGE! You would not believe how many of theses I get! :)
oMSG.To = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.From = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.Subject = "Hello Email"
oMSG.AddAttachment(“c:\myfile.txt”)
oMSG.AddAttachment(“c:\MySecondFile.gif”)
oMSG.Send()
Here is a great way to embed your web page in your email:
oMSG = createobject("CDO.Message")
** DO NOT FORGET TO CHANGE! You would not believe how many of theses I get! :)
oMSG.To = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.From = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.Subject = "Hello Email"
oMSG.CreateMHTMLBody("http://www.cnn.com")
oMSG.Send()
Here is another way to send HTML in your email:
oMSG = createobject("CDO.Message")
** DO NOT FORGET TO CHANGE! You would not believe how many of theses I get! :)
oMSG.To = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.From = "jordanbaumgardnerNOMATCH@earthlink.net"
oMSG.Subject = "Hello Email"
oMSG.HTMLBody = [< b >< P >< FONT COLOR="#CC0000" >Hello In Color< /FONT >< /b >]
oMSG.Send()
I hope this helps. It has sure saved me a lot of time.
For a complete listing of all the Properties and Methods in the CDO.Message, go to:
http://msdn.microsoft.com/library/psdk/cdosys/_cdosys_imessage_interface.htm
Here's the new link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/39186eaa-c4c1-430a-9715-35e291925c5c.asp - DD
If I can help in any way, please email me at:
Jordanbaumgardner@earthlink.net
This is indeed easier than most of the other methods I've tried. Thanks for the code.
Like a lot easier!! I'm moving some things from the "too complicated" pile to the "can do" pile...
Can you use CDO to read existing emails? For example, if an email is in the inbox can CDO read the header of that email to see what IP it came from?

Yes you can! I uploaded a file Mail.zip to the fox wiki ftp site. This was written in 1997, so there may be new features not implemented. Documentation is in the zip.

Craig Boyd's blog article: 13 Jul 05 Email and VFP: Part 1d (CDO NTS)
http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,40a6327a-44f7-4e98-9e83-cb50c2ebd4c1.aspx
The Microsoft link mentioned above (
http://msdn.microsoft.com/library/psdk/cdosys/_cdosys_imessage_interface.htm) is broken. (I don't know why Micorsoft keeps shuffling documents!). Could anyone provide a working link. (Even email to
Jordanbaumgardner@earthlink.net did not go through!)
I have used CDO Mail. It works fine. I have only one problem. I have not been able to change the importance/priority of the mail message. Has anyone been been able to change priority with CDO so that a message sent through CDO mail appears with Importance = High in Outlook? I tried the following commands but all messages appear as 'Normal".
.Item("urn:schemas:httpmail:importance") = 2
.Item("urn:schemas:mailheader:importance") = "High"
.Item("urn:schemas:httpmail:priority") = 1
.Item("urn:schemas:mailheader:priority") = 1
.Item("urn:schemas:mailheader:X-MSMail-Priority") = 0
.Item("urn:schemas:mailheader:X-Priority") = 1
- Ravi
Here's how to set the priority, including a more complete code sample than I posted previously.
This works for me under
Win XP SP2 when used in conjuction with MS Exchange Server 5.5. I have not tested in other scenarios.
LOCAL loConfig AS CDO.Configuration, loFlds AS Object, loMsg AS CDO.Message
loConfig = CREATEOBJECT("CDO.Configuration")
loFlds = loConfig.Fields
WITH loFlds
*- Set the CDOSYS configuration fields to use port 25 on the SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort && 25
*- Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MySMTPServer"
*- Assign timeout in seconds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
*- Commit changes to the object
.Update()
ENDWITH
*- Create and send the message.
loMsg = CREATEOBJECT("CDO.Message")
WITH loMsg
.Configuration = loConfig
.To = "sample@somedomain.com"
.From = "sender@mydomain.com"
.Subject = "This is a test of CDO sending e-mail"
.HTMLBody = "This is the HTML content of the mail message"
*- Set priority to HIGH if needed
IF tlUrgent
.Fields("Priority").Value = 1 && -1=Low, 0=Normal, 1=High
.Fields.Update()
ENDIF
.Send()
- Bruce Allen
Hi Bruce,
I tried your suggestion. It does not change the priority and I continue to see "normal priority" in the message viewed in Outlook. I am not sure if it has anything to do with CDO version. I am using Windows XP Professional with all latest updates. I don't remember downloading CDO. Here is my code.
loMsg = Createobject("CDO.Message")
loMsg.Fields("Priority").Value = 1 && 1 = High, 0 = Normal
loMsg.Fields.Update()
iConf = Createobject("CDO.Configuration")
Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = lcMailServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 90
.Update
ENDWITH
With loMsg
.Configuration = iConf
.To = lcToAddress
* Define other message parameters ....
.Send
ENDWITH
- Ravi
We had an issue where we needed to speed up our SMTP services and used CDOSYS to test. Wow! Hightly recommended -
Doug Dodge
CDO with VFP and Gmail / Google Apps
TRY
LOCAL lcSchema, loConfig, loMsg, loError, lcErr
lcErr = ""
lcSchema = "http://schemas.microsoft.com/cdo/configuration/"
loConfig = CREATEOBJECT("CDO.Configuration")
WITH loConfig.FIELDS
.ITEM(lcSchema + "smtpserver") = "smtp.gmail.com"
.ITEM(lcSchema + "smtpserverport") = 465 && ó 587
.ITEM(lcSchema + "sendusing") = 2
.ITEM(lcSchema + "smtpauthenticate") = .T.
.ITEM(lcSchema + "smtpusessl") = .T.
.ITEM(lcSchema + "sendusername") = "usuario@gmail.com"
.ITEM(lcSchema + "sendpassword") = "contraseña"
.UPDATE
ENDWITH
loMsg = CREATEOBJECT ("CDO.Message")
WITH loMsg
.Configuration = loConfig
.FROM = "usuario@gmail.com"
.TO = "usuario@hotmail.com"
.Subject = "Prueba desde Gmail"
.TextBody = "Este es un mensaje de prueba con CDO con " + ;
"autenticación y cifrado SSL desde Gmail"
.Send()
ENDWITH
CATCH TO loError
lcErr = [Error: ] + STR(loError.ERRORNO) + CHR(13) + ;
[Linea: ] + STR(loError.LINENO) + CHR(13) + ;
[Mensaje: ] + loError.MESSAGE
FINALLY
RELEASE loConfig, loMsg
STORE .NULL. TO loConfig, loMsg
IF EMPTY(lcErr)
MESSAGEBOX("El mensaje se envió con éxito", 64, "Aviso")
ELSE
MESSAGEBOX(lcErr, 16 , "Error")
ENDIF
ENDTRY
Article published in
Portal Fox (in Spanish)
Envío de correo electrónico por el servidor SMTP de Gmail
http://www.portalfox.com/article.php?sid=2413
--
Luis Maria Guayan
See also
Automated Email
Category ActiveX Category Code Samples