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
ELSE
	? "Email sent."
ENDIF

See Also Send email via Gmail account

No votes yet