Send Mail : Examples
Sending e-mails with Visual Foxpro
(The download includes a form that allows generating sample code)
Hello World
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.SMTP_HOST = "smtp.serveur.com"
o.FROM = "mon_email@serveur.com"
o.TO = "ton_email@serveur.com"
o.Subject = "Hello World"
o.Message = "Hello World..."
IF NOT o.send()
? "Erreur : " + o.Erreur
ENDIF
o=Null
Hello World with default mailer values and Dump file if problem
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.TO = "ton_email@serveur.com"
o.Subject = "Hello World"
IF NOT o.send()
? "Erreur : " + o.Erreur
MODIFY FILE o.Dump("c:\temp\dump.txt")
ENDIF
o=Null
Hello World 2
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.SMTP_HOST = "smtp.Serveur.com"
o.FROM = "mon_email@serveur.com"
o.FROM_NAME = "Mon Nom"
o.TO = "ton_email@serveur.com, autre_email@serveur.com"
o.cc = "copie_email@serveur.com"
o.cc_name = "Nom du Copie"
o.Subject = "Hello World"
o.Message = "Hello World..."
IF NOT o.send()
? "Erreur : " + o.Erreur
ENDIF
o=Null
Message with attachment
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.SMTP_HOST = "smtp.Serveur.com"
o.FROM = "mon_email@serveur.com"
o.FROM_NAME = "Mon Nom"
o.TO = "ton_email@serveur.com"
o.Subject = "Hello World"
o.Message = "Ci joint..."
o.attachment = "c:\temp\fichier1.jpg, c:\temp\fichier2.jpg"
IF NOT o.send()
? "Erreur : " + o.Erreur
ENDIF
o=Null
Use of ESMTP (authentification for the sending email)
If the email server is not in open relay, an authentication is required:
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.SMTP_HOST = "smtp.mail.yahoo.fr"
o.FROM = "my_email@domaine.com"
o.TO = "your_email@domaine.com"
o.Subject = "Hello World"
o.Message = "Test..."
o.Auth_Login = "login"
o.Auth_password = "password"
IF NOT o.send()
? "Error : " + o.Erreur
ENDIF
o=Null
Sending Email with a message body resulting from MHTML file generated by XFRX
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.SMTP_HOST = "smtp.Serveur.com"
o.FROM = "mon_email@serveur.com"
o.FROM_NAME = "moi"
o.TO = "ton_email@serveur.com"
o.TO_NAME = "toi"
o.Subject = "Fichier MHTML"
o.data_mhtml = "c:\temp\monfichier.mht"
IF NOT o.send()
? "Erreur : " + o.Erreur
ENDIF
o=Null
Combining the above examples: ESMTP + body MHTML generated by XFRX + Attachments
SET PROCEDURE TO VFPwinsock
o=CREATEOBJECT("VFP_Winsock_Send_Mail")
o.SMTP_HOST = "smtp.mail.yahoo.fr"
o.FROM = "mon_email@yahoo.fr"
o.FROM_NAME = "moi"
o.TO = "ton_email@serveur.com"
o.TO_NAME = "toi"
o.Subject = "Génial"
o.data_mhtml = "c:\temp\monfichier.mht"
o.Auth_Login = "login"
o.Auth_password = "passe"
o.attachment = "c:\temp\fichier1.jpg, c:\temp\fichier2.jpg"
IF NOT o.send()
? "Erreur : " + o.Erreur
ENDIF
o=Null