SMTP with authentication

Post Reply
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

SMTP with authentication

Post by cdmmaui »

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,
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Darrell,

There is a modification for FWH Class TSmtp but it looks as it does not work properly on all circunstances.

As Rene suggested, you may use funcky SMTP component as it supports authentication.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Post by cdmmaui »

Hi Antonio,

Where can I obtain the funky SMTP component?

Thank you,
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
E. Bartzokas
Posts: 114
Joined: Tue Feb 14, 2006 8:13 am
Location: Corinth, Greece

Post by E. Bartzokas »

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
We use MarshallSoft's SEE32 (32-bit) DLL
It supports authentication, and it's easy to use.
If anyone wants to test it, download from www.marshallsoft.com, and
ask me for the wrappers.

Kind regards
Evans
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Post by cdmmaui »

Hi Evans,

I own SEE32 also but I was told it does not work with FWH? Did you get it to work with FWH?
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
E. Bartzokas
Posts: 114
Joined: Tue Feb 14, 2006 8:13 am
Location: Corinth, Greece

Post by E. Bartzokas »

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?
Hi cdmmaui (sorry, but it's a difficult name)
:wink:

Yes, we use SEE32 since our program was in 16 bit. Later on, we converted to 32-bit DLL (SEE32.DLL), and of course, now with xHarbour and FWH, we use the 32 bit without any changes to our code.

I can email you some samples (abstracts from our code to send emails), including the authentication (some newer version of SEE32 supports authentication too, and we have it).

It's not difficult to use it, especially because I have created a great wrap-around code in one simple .PRG file where I am using the SEE32.DLL without having to load/unload it all the time.

We are very satisfied with the library, although sometimes -very rearly- we get a winsock error - but like I said, it's very limited.... for example in about 200 machines that it is used, I have found 3-4 problems only, and those were finally solved, because our clients did not use the correct setu-up (pop3 and smtp) for sending email... It was so simple to fix the problem, just copy and paste their setup from outlook or netscape, etc. !

Anyway, if you need some code to get you going with SEE32.DLL in FWH/xHarbour, please send me a personal email I could reply to. This applies to all of our friends who would like some help in using this specific DLL.

Regards
Evans
User avatar
AlexSchaft
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

SMTP Authentication

Post by AlexSchaft »

Hi,

We successfully do "plain" (mime encoded) authentication.

Below an extract from our modified smtp class:

Code: Select all

#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
jbinfo
Posts: 7
Joined: Mon Aug 28, 2006 1:33 pm
Location: Brazil

Post by jbinfo »

We use the Matteo Baccan internet classes for xharbour!

It works fine, and the source of the project is open.... You don't have to depend of dlls or libs.. Try this, I'm sure you will not regret.

http://www.baccan.it

There you can download a zip format file that comes with the source and some samples, the class is called xHarbour TSocket (1.05) and it englobes other minor classes. Try looking at the TSmtp Class which allows you to use authentication and many other options.
The Matteo Baccan's website is unstable sometimes, so if you want I can send you the file by e-mail..

Best regards..
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

Hi Evans,

Does the SEE32 library support sending HTML as well?
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
R.F.
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Post by R.F. »

Funcky is the way to go, support everything, authentication, htm support, and e-mail existing routines.

A little pricy, but worth the price.

www.funcky.com
Saludos
R.F.
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

Ok, dumb question - which one? for C++ for Xbase++ ?
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
R.F.
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Post by R.F. »

Ollie:

Look for the COM component (Delphi, VB, BC++) works via OLE, here a sample:

http://www.google.d2g.com/funckydemo.zip

Regards

RF
http://www.google.com
Saludos
R.F.
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

ok
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Post Reply