La Web del Programador: Comunidad de Programadores
 
    Pregunta:  63921 - MANDAR MAIL CON ARCHIVO (INFORME EN PDF) DESDE UN BOTON
Autor:  Marcos azzano
Hola quisiera saber como mandar un mail desde VFP9 con un archivo adjunto o haciendo click en boton me habra el outlook ya con el archivo adjutado. Gracias

  Respuesta:  Juan Dietz
********************************************************************************
*** Mandar un mail, recibe el texto y la ruta del archivo a enviar
********************************************************************************
FUNCTION Enviar_Mail(mC_Comentario, mC_Archivo)
DECLARE LONG InternetGetConnectedState IN "wininet.dll" ;
LONG lpdwFlags, LONG dwReserved
IF InternetGetConnectedState(0, 0) = 1 &&si hay conexion a internet
loCfg = CREATEOBJECT("CDO.Configuration")
WITH loCfg.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.live.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" &&Cambiar por tu cuenta
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" &&Cambiar por tu cuenta
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = .T.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .T.
.Update
ENDWITH
loMsg = CREATEOBJECT ("CDO.Message")
WITH loMsg
.Configuration = loCfg
.From = "[email protected]"
.To = "[email protected]" &&Cuenta destino
IF !EMPTY(mC_Archivo) &&ruta del archivo
.AddAttachment(mC_Archivo)
ENDIF
.Subject = "hola" &&Asunto
.TextBody = mC_Comentario
.Send()
ENDWITH
**********
ELSE
MensajeNoWait('Sin Conexion a Internet')
ENDIF
ENDFUNC