#INCLUDE wconnect.h
LOCAL loSmtp 
CLEAR

*** Load required libraries
DO wwSmtp 

LOCAL loSmtp as wwSmtp
loSmtp = CREATEOBJECT("wwSmtp")

*** Select mail mode. 0 - .NET wwSmtp  2 - Classic wwIPstuff (default)
*** Note: Mode 2 only supports SendMail and SendMailAsync
***       and no support for alternate views
loSmtp.nMailMode = 2

*** Google SMTP server - requires login and SSL/TLS
loSmtp.cMailServer = "asmtp.test.net"   && add a port number with :587
*loSmtp.cMailServer = "localhost"

*** Timeout in seconds
loSmtp.nTimeout = 25

*** Optionally use SSL/TLS if the mail server requires it
loSmtp.lUseSsl = .F.

*** Specify user name and password if auth is required
*!*	loSmtp.cUsername = "yourname22@gmail.com"
*!*	loSmtp.cPassword = "seekret"
loSmtp.cUserName = "yourname22@gmail.com"
loSmtp.cPassword = "seekret"


loSmtp.cSenderName= "wwIPstuff Samples"
loSmtp.cSenderEmail = "support@mydomain.com"

*** The following are all comma delimited recipient lists of email addresses
*** you can optionally use "Name" <email@address.com> as the format to
*** have a display name
loSmtp.cRecipient = [jimmyd@mydomain.com,"John" <johndoe@mydomain.com>]


*** Optional CC and BCC lists or recipients
*loSmtp.cCCList = ["Bill" <billyboy@mydomain.com>,frankie@mydomain.com]
*loSmtp.cCCList = [billyboy@mydomain.com>]

*** Actual message properties
loSmtp.cSubject = "wwSMTP Test Message"
loSmtp.cMessage = "<b>HTML Test message from wwsmtp, to check out how this operation works.</b>"

*** If cMessage contains HTML set cContentType to text/html
loSmtp.cContentType = "text/html"

*!*	loSmtp.cAlternateContentType = "text/plain"
*!*	loSmtp.cAlternateText = "Here is alternate content in plain text."

*** Optional properties
loSmtp.cReplyTo = "james@mydomain.com"
loSmtp.cPriority = "Normal"

*** To add attachments use Attachment and point at a full file path
*loSmtp.AddAttachment("c:\sailbig.jpg")
*loSmtp.AddAttachment("c:\photos\sailbig_original.jpg","image/jpeg")


*** Add any custom headers that properties don't cover
* loSmtp.AddHeader("custom-header","SecretKey Goes here")

*** Adding an alternate view allows embedding images into the message
*!*	LOCAL loAlternateView as AlternateView
*!*	loAlternateView = CREATEOBJECT("wwSmtpAlternateView")
*!*	loAlternateView.cText = "<b>Hello</b> World! <img src='cid:sailbig' />"
*!*	loAlternateView.cContentType = "text/html"
*!*	loAlternateView.AddLinkedResource("c:\photos\sailbig.jpg","image/jpeg","sailbig")
*!*	loSmtp.AddAlternateView( loAlternateView )

*** Single Mail Sending - connect/disconnect for message
#IF .T.
	llResult = loSmtp.Sendmail()
	IF llResult
	   WAIT WINDOW "Mail sent..." nowait
	ELSE
		? "Mail sending failed: " 
		? loSmtp.cErrorMsg
	ENDIF	
#ENDIF

*** Multiple Mail Sending - send multiple messages on a single connection
*** this is faster if sending many messages.
*** First send connects to server
*** and connection stays open until Close is called
*** 
*** Only works in .NET mode (nMailMode = 0)
#IF .F.
	*** Must manually connect first
	loSmtp.Connect()


	*loSmtp.AddAttachment("c:\temp\trace.txt")
	
	*loSmtp.cAttachment = "c:\temp\trace.txt"
	
	*** Send first recipient
	?loSmtp.SendMessage("jjimy44@hotmail.com","","")	
	? loSmtp.cErrorMsg

	loSmtp.ClearAttachments()
	loSmtp.AddAttachment("c:\temp\trace.txt")
	
	*** Change a few things for second message
	*loSmtp.cAttachment = "c:\temp\trace2.txt"
	loSmtp.cSubject = "Message number two"
	?loSmtp.SendMessage("jjimy55@hotmail.com","","")
	? loSmtp.cErrorMsg

	*** Must close connection
	loSmtp.Close()
#ENDIF

? "Done..."