Hello,
Is it possible to use TSMTP class and send email automatically (without Outlook) with from user authentication? If so, can you provide sample code?
Thank you,
Antonio Linares wrote:Darrell,
www.funcky.com
Anyhow, here you have the Class TSmtp from FiveWin modified to support authentication by Luis Krause:
http://fivetechsoft.com/forums/viewtopi ... entication
cdmmaui wrote:Hi Evans,
I own SEE32 also but I was told it does not work with FWH? Did you get it to work with FWH?
#define ST_INIT 0
#define ST_CONNECTED 1
#define ST_RESET 2
#define ST_MAILFROM 3
#define ST_RCPTTO 4
#define ST_DATA 5
#define ST_SENT 6
#define ST_QUIT 7
#define ST_DONE 8
#define ST_ERROR 9
// AS 08/09/2005 New status code for authentication
#define ST_AUTH 10
::lSimpleSMTP := file(FixPath(cExepath()) + "HELOSMTP.MSG")
METHOD OnRead( oSocket ) CLASS qSmtp
/*
Handles receiving data from the mail server and responding to it
*/
Local cData := oSocket:Getdata()
Local n := 0
Local nCount := 0
Local nStop := 0
Local cCC := ""
Local cReply := left(cData, 3)
Local nPos := 0
Local cTempFileTemplate := ""
Local cTempMimeFile := ""
Local aMimeFiles := {}
Local cMailHeader := ""
Local cNextPartHeader := ""
Local cTempMsgMimeFile := ""
Local lMultiPart := .f.
Local lHtmlMsg := ""
Local lHtmlMsgFile := ""
Local nNow := 0
// PK 29/08/2005
Local nRemSeconds := 0
// Buffer received data, as you do not necessarily receive all the server data in one go e.g.
::cReceived += cData // cReceived is built up until it is a complete server response
// Pull out full lines received
Do While at(CRLF, ::cReceived) > 0
nPos := at(CRLF, ::cReceived)
// Build up an array of all the server replies
aadd(::acReply, left(::cReceived, nPos - 1))
::cReceived := substr(::cReceived, nPos + 2)
Enddo
// Has closing line been received i.e. full reply from server (may come in dribs and drabs)
If substr(atail(::acReply), 4, 1) == " "
// We now have the full server response, now process it.
// AS 08/09/2005
cReply := substr(atail(::acReply), 1, 3)
If ::lLog
// AS 08/09/2005
aeval(::acReply, {|pcReply| LogFile(::cLogFile, {"SERVER: " + pcReply})})
// LogFile(::cLogFile, {"MAILSERVER (Status = " + NTRIM(::nStatus)+"): " + cReply})
Endif
Do Case
Case ::nStatus == ST_INIT
If cReply == "220" // Server acknowleges connection
// Send helo and hop to next status
::nStatus := ST_CONNECTED
// AS 20/01/2006
If ::lSimpleSMTP
::SendData("HELO " + strtoken(::cFrom, 2, "@") + CRLF )
Else
// AS 08/09/2005 Enhanced response request (causes server to list capabilities, and requirements)
::SendData("EHLO " + strtoken(::cFrom, 2, "@") + CRLF )
Endif
If ::bConnected != nil
eval( ::bConnected )
Endif
Else
::Failure(atail(::acReply))
Endif
Case ::nStatus == ST_CONNECTED
// We are connected
Do Case
Case cReply == "250" // Server happy
// Send mail from and hop to next status
// AS 08/09/2005 Check if authentication is indicated in the reply, and see if our supported method of authentication is accepted
//
If (nPos := ascan(::acReply, {|pcReply| left(pcReply, 8) == "250-AUTH"})) > 0 ;
.and. !empty(::cEmailUser) // PK 03/10/2005, only try authenticate if a user name is setup
// We need to authenticate, but can we handle it?
If at("LOGIN", ::acReply[nPos]) > 0
// We can do it
// AS 22/09/2005 Check if we have user name and password
If empty(::cEmailUser) .or. empty(::cEmailPassword)
::Failure("The email server requires authentication, but the user name and/or password are blank.")
Else
::cAuthType := "LOGIN"
::nStatus := ST_AUTH
::SendData("AUTH LOGIN" + CRLF)
Endif
Else
::Failure("Unsupported authentication method")
Endif
Else
// Previous code
::nStatus := ST_MAILFROM
::SendData(strtran( "MAIL FROM:<%>", "%", ::cFrom ) + CRLF )
::nTo := 1 // First recipient index to send mail to
Endif
// AS 20/01/2006 Cater for servers not understanding EHLO command
Case cReply == "500" // Server said "Say what?"
If !::lSimpleSMTP
// Try Simple SMTP
::lSimpleSMTP := .t.
::SendData("HELO " + strtoken(::cFrom, 2, "@") + CRLF )
Else
// Simple failed
::Failure(atail(::acReply))
Endif
Otherwise
::Failure(atail(::acReply))
Endcase
// AS 08/09/2005 Manage authentication
Case ::nStatus == ST_AUTH
Do Case
Case cReply == "334"
Do Case
Case ::cAuthType == "LOGIN"
// We're logging in
If !::lSentUser
::lSentUser := .t.
::SendData(cmimeenc(alltrim(::cEmailUser)) + CRLF)
Else
If !::lSentPassword
::lSentPassword := .t.
::SendData(cmimeenc(alltrim(::cEmailPassword)) + CRLF)
Endif
Endif
Endcase
Case cReply == "235"
// Authentication OK
::nStatus := ST_MAILFROM
::SendData(strtran( "MAIL FROM:<%>", "%", ::cFrom ) + CRLF )
::nTo := 1 // First recipient index to send mail to
// PK 22/09/2005
// CASE cReply == "501"
Case cReply == "501" .or. left(cReply, 3) == "535"
// Authentication failure
::Failure("Authentication failure")
Otherwise
::Failure(atail(::acReply))
Endcase
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 49 guests