Send email via Yahoo mail account

Yahoo SMTP server requires SSL connection on port 465.

Sample code below uses CDO 2000 class for sending emails

This is sample code. Add error handling and adjust to your requirements as necessary.

* Replace addresses with real ones before running the code
 
loMail = NEWOBJECT("Cdo2000", "Cdo2000.fxp")
 
WITH loMail
	.cServer = "smtp.mail.yahoo.com"
	.nServerPort = 465
	.lUseSSL = .T.
 
	.nAuthenticate = 1 	&& cdoBasic
 	.cUserName = "yourYahooAccount@Yahoo.com"
	.cPassword = "yourYahooPassword"
 
	* The From address has to be one the registered identities (Yahoo accounts),
	*.cFrom = "yourYahooAccount@Yahoo.com"
 
	.cFrom = .cUserName
 
	.cTo = "somebody@otherdomain.com, somebodyelse@otherdomain.com"
 	.cSubject = "CDO 2000 email through Yahoo SMTP server"
 
	* Uncomment next lines to send HTML body
	*.cHtmlBody = "<html><body><b>This is an HTML body<br>" + ;
	*		"It'll be displayed by most email clients</b></body></html>" 	
 
	.cTextBody = "This is a text body." + CHR(13) + CHR(10) + ;
			"It'll be displayed if HTML body is not present or by text only email clients"
 
	* Attachments are optional
	* .cAttachment = "myreport.pdf, myspreadsheet.xls"
ENDWITH
 
IF loMail.Send() > 0
	FOR i=1 TO loMail.GetErrorCount()
		? i, loMail.Geterror(i)
	ENDFOR
	* Clear errors
	loMail.ClearErrors()
ELSE
	? "Email sent."
ENDIF

$SEEALSO$ Send email via Gmail account

Comments

My problemn is this: I'm trying to transform a report output in Vfp9 to a .htm file. This I do with the HTMLListener.

LOCAL oHtml
SET PATH TO (HOME() + "FFC") ADDITIVE
oHtml = NEWOBJECT("HtmlListener","_reportlistener.vcx")
oHtml.TargetFileName = "c:\caja\datos\Informe.htm"
oHtml.QuietMode = .T.
oHtml.xsltParameters = CREATEOBJECT("Collection")
oHtml.xsltParameters.Add(6, "numberPrecision")
oHtml.externalFileLocation = ".\images"
oHtml.copyImageFilesToExternalFileLocation = .T.
REPORT FORM total_xcuenta OBJECT oHtml

I get the file "Informe.htm". If I click on it the explorer opens and there it is, my vfp report in it.

Then I try to send a mail with my .htm file displayed in it.

OCAL ceMailRemitente as String, cContrasena as String, cTitulo as String, cTexto as String
ceMailRemitente = "olgagaya@GMAIL.com"
cContrasena = "PaulaSunde"
cTitulo = "Caja - Totales x cuenta === Período " + DTOC(thisform.txtFechaInicial.Value) + " - " + DTOC(thisform.txtFechaFinal.Value)
cTexto = "tita 8"

LOCAL cEsquema as String, oCDO as Object, oMsg as Object, oError as Object
cEsquema = "http://schemas.microsoft.com/cdo/configuration/"

TRY
oCDO = CREATEOBJECT("CDO.Configuration")
oMsg = CREATEOBJECT("CDO.Message")

WITH oCDO.Fields
DO CASE
CASE "GMAIL" $ Upper(ceMailRemitente)
.Item(cEsquema + "smtpserver") = "smtp.gmail.com"
.Item(cEsquema + "smtpserverport") = 465
.Item(cEsquema + "sendusing") = 2
.Item(cEsquema + "smtpauthenticate") = .T.
.Item(cEsquema + "smtpusessl") = .T.
OTHERWISE
WAIT WINDOW NOWAIT "No puedo enviar este e-mail. No conozco los parámetros necesarios del servidor de correo"
ENDCASE

.Item(cEsquema + "sendusername") = ceMailRemitente
.Item(cEsquema + "sendpassword") = cContrasena
.Update()
ENDWITH

WITH oMsg
.Configuration = oCDO
.From = "Olga Gaya "
.To = thisform.cDestinatarios
.Subject = cTitulo

.CreateMHTMLBody("file://c:\caja\datos\informe.htm", 0)

.Fields.Update
.Send()

WAIT WINDOW NOWAIT 'Los eMails para ' + thisform.cNombres + ' fueron enviados exitosamente.'
ENDWITH

CATCH TO oError
MESSAGEBOX("No pudieron enviarse los eMails" + CHR(13) + "Error Nº: " + TRANSFORM(oError.ErrorNo) + CHR(13) + "Mensaje: " + oError.Message)
FINALLY
ENDTRY

And it works. Or almost. Because the page looses its format. Everything is placed on the left side.
Do you know why the file is not displayed as originally?

Thanks for any answer
Hernan

when i send email from my pc then email delivered successfully but i try on another computer then why shows an err message that "oHTML is an object" and message not delivered. i use vfp9.0 with cdo2000.

Send email via Lotus Domino
is this possible?
How?
Thanks anticipated !!!

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.