Alaska Software Inc. - EMAIL PROBLEM
Username: Password:
AuthorTopic: EMAIL PROBLEM
James LoughnerEMAIL PROBLEM
on Fri, 05 Aug 2022 12:20:15 -0400
Trying to set up a smtp client for a client using port 465 and/or 587. TLS

want to attach to MS email and or gamil

This is a replacement for current email that only supports port 25

Attached is the log. Log is for another client that works wit SEE lib

Jim

CODE

Function 
Send_EmailXB(cSmtpFrom1,cSmtpServer1,cSmtpPort1,cSmtpUser1,cSmtpPass1,cSmtpTo1,cUserPath1,cSubject1,cMsg,cAttachment1,cSmtpReply1,cHTMLFIle,cCCEmail)
LOCAL lRtn := .T., 
oSmtp,oSender,oRecipient,oMail,cText,nPort,cHost,I,cFile:="",aAttach:={}
LOCAL oLog:= LogWriter():new("LASTEMAILERROR.log")
  AltD()
    cSmtpFrom1 := STRTRAN(cSmtpFrom1,"<","")    remove <>
    cSmtpFrom1 := STRTRAN(cSmtpFrom1,">","")
    cHost := LEFT(cSmtpFrom1,AT("@",cSmtpFrom1)-1)   //home ISP

    cSmtpServer1 := STRTRAN(cSmtpServer1,"<","")    remove <>
    cSmtpServer1 := STRTRAN(cSmtpServer1,">","")

    cSmtpPort1 := STRTRAN(cSmtpPort1,"<","")    remove <>
    cSmtpPort1 := STRTRAN(cSmtpPort1,">","")
    nPort := VAL(cSmtpPort1)

    cSmtpUSER1 := STRTRAN(cSmtpUSER1,"<","")    remove <>
    cSmtpUSER1 := STRTRAN(cSmtpUSER1,">","")

    cSmtpPASS1 := STRTRAN(cSmtpPASS1,"<","")    remove <>
    cSmtpPASS1 := STRTRAN(cSmtpPASS1,">","")

    cSmtpTo1   := STRTRAN(cSmtpTo1,"<","")    remove <>
    cSmtpTo1   := STRTRAN(cSmtpTo1,">","")

    cSubject1  := STRTRAN(cSubject1,"<","")    remove <>
    cSubject1  := STRTRAN(cSubject1,">","")

    cAttachment1 := STRTRAN(cAttachment1,"<","")    remove <>
    cAttachment1 := STRTRAN(cAttachment1,">","")

    cSmtpReply1 := STRTRAN(cSmtpReply1,"<","")    remove <>
    cSmtpReply1 := STRTRAN(cSmtpReply1,">","")

    cHTMLFIle := STRTRAN(cHTMLFIle,"<","")    remove <>
    cHTMLFIle := STRTRAN(cHTMLFIle,">","")

    cCCEmail := STRTRAN(cCCEmail,"<","")    remove <>
    cCCEmail := STRTRAN(cCCEmail,">","")

     Parse out attacment files format File1;File2;....
    FOR I = 1 TO LEN(cAttachment1)
        IF cAttachment1[I] = ";" .OR. I=LEN(cAttachment1)
           AADD(aAttach,cFile)
           cFile := ""
           ++I
           LOOP
        ENDIF
        cFile += cAttachment1[I]
    NEXT I

     Connect to the Windows Live SMTP server. Port number
     587 implies a secure SSL connection. Use standard
     port 25 for unencrypted communication and for
     servers which do not support SSL.
    
    oSmtp      := SMTPClient():new( cSmtpServer1, nPort,cHost,;
                                          oLog, 2 )

    oSender    := MailAddress():new( cSmtpFrom1 )
    oRecipient := MailAddress():new( cSmtpTo1 )
    oMail      := MIMEMessage():new()
    cText      := cMsg

    oMail:setFrom     ( oSender     )
    oMail:setSubject  ( cSubject1 )
    oMail:setMessage  ( cText       )
    oMail:addRecipient( oRecipient  )

    oMail:addHeader( "CC", cCCEmail  )
    FOR I = 1 TO LEN(aAttach)
       IF FILE(aAttach[I])
          oMail:AddFile(aAttach[I])
       ELSE
          MPMMsgBox("Attached file not found "+CHR(13)+aAttach[I]+" Not 
attached","Attachment failed")
          oLog:logError( "Attached file not found 
"+aAttach[I]+CHR(13)+"Not attached" )
       ENDIF
    NEXT I

    IF oSmtp:connect( cSmtpFrom1, cSmtpPASS1 )
       IF !oSmtp:send( oMail )
          mpmmsgbox("Unable to deliver message","Email Error SMTP",.T.) 
 desktop parent
          oLog:logError( "Unable to deliver message" )
          lRTn := .F.
       ENDIF
       oSmtp:disconnect()
    ELSE
       mpmmsgbox("Unable to connect to mail server","Email Error 
SMTP",.T.)   desktop parent
       oLog:logError( "Unable to connect to mail server" )
       lRTn := .F.
    ENDIF

    IF .NOT. oLog:isError()
       oLog:write( "NO ERROR" )
    ENDIF

    oLog:writeLogFile()
RETURN lRtn


    /*
     * User-defined class for log-data processing
     */
CLASS LogWriter
    VAR lIsError
    VAR aMessage
    VAR cLogFile

  EXPORTED:

    INLINE METHOD init( cLogFile )
       ::cLogFile := cLogFile
       ::aMessage := {}
       ::lIsError := .F.
    RETURN


    INLINE METHOD write( cMsg )
       AAdd( ::aMessage, cMsg )
    RETURN self


    INLINE METHOD logError( cMsg )
       ::lIsError := .T.
       ::write( cMsg )
    RETURN self


    INLINE METHOD isError
    RETURN ::lIsError


    INLINE METHOD writeLogFile
       LOCAL nHandle

       IF .NOT. FExists( ::cLogFile )
          nHandle := FCreate( ::cLogFile )
       ELSE
          nHandle := FOpen( ::cLogFile )
          FSeek( nHandle, 0, FS_END )
       ENDIF

       AEval( ::aMessage, {|cMsg| FWrite( nHandle, cMsg + CRLF ) } )
       FClose( nHandle )
    RETURN self

ENDCLASS


LASTEMAILERROR.log
Andreas Gehrs-Pahl
Re: EMAIL PROBLEM
on Sun, 07 Aug 2022 18:29:29 -0400
James,

Your program and log file don't show which port you are using. I assume 
that you use port 465, which is the "implicit" TLS port, which creates an 
(implicit) SSL connection before any text is sent. The log file indicates 
no problems with connecting on the chosen port, though, even if it was 587 
(which would require a StartTLS command, but that isn't in the log file).

The SMTP server sends a 334 response challenge to your "AUTH LOGIN" request:

> Info: Send: AUTH LOGIN
> Info: Recv: 334 VXNlcm5hbWU6 (==> "Username:" Base64 encoded)

Your program then sends the user name: office@colebrooknewsandsentinel.com

> Info: Send: b2ZmaWNlQGNvbGVicm9va25ld3NhbmRzZW50aW5lbC5jb20=

Then the server asks for the password:
> Info: Recv: 334 UGFzc3dvcmQ6 (==> "Password:" Base64 encoded)

to which your program responds with sending the (Base64 encoded) password:

> Info: Send: dDVqc3ZhRyRuRjQ1biZo (==> "t5jsvaG$nF45n&h" Base64 encoded)

The server then responds with the 535 error message "Authentication failed", 
because the username and/or password are incorrect.

> Info: Recv: 535 Authentication failed

You should verify that the username and password are correct (and don't post 
them on an open forum, like this one, even if they are Base64 encoded). 

If you get an 530 error response, then you probably connected on port 587 
and need to send an StartTLS command, before you can log in.

If you get an 538 error response, then you probably didn't connect on port 
465, but need an (implicit) SSL connection, before you can log in.

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
James LoughnerRe: EMAIL PROBLEM
on Mon, 08 Aug 2022 09:30:18 -0400
Thanks Andreas This example did use 465 but the same errors seem to be 
586. Hmmm since PW is base 64 maybe I need to trim it before sending?????

Jim


On 8/7/22 6:29 PM, Andreas Gehrs-Pahl wrote:
> James,
> 
> Your program and log file don't show which port you are using. I assume
> that you use port 465, which is the "implicit" TLS port, which creates an
> (implicit) SSL connection before any text is sent. The log file indicates
> no problems with connecting on the chosen port, though, even if it was 587
> (which would require a StartTLS command, but that isn't in the log file).
> 
> The SMTP server sends a 334 response challenge to your "AUTH LOGIN" request:
> 
>> Info: Send: AUTH LOGIN
>> Info: Recv: 334 VXNlcm5hbWU6 (==> "Username:" Base64 encoded)
> 
> Your program then sends the user name: office@colebrooknewsandsentinel.com
> 
>> Info: Send: b2ZmaWNlQGNvbGVicm9va25ld3NhbmRzZW50aW5lbC5jb20=
> 
> Then the server asks for the password:
>> Info: Recv: 334 UGFzc3dvcmQ6 (==> "Password:" Base64 encoded)
> 
> to which your program responds with sending the (Base64 encoded) password:
> 
>> Info: Send: dDVqc3ZhRyRuRjQ1biZo (==> "t5jsvaG$nF45n&h" Base64 encoded)
> 
> The server then responds with the 535 error message "Authentication failed",
> because the username and/or password are incorrect.
> 
>> Info: Recv: 535 Authentication failed
> 
> You should verify that the username and password are correct (and don't post
> them on an open forum, like this one, even if they are Base64 encoded).
> 
> If you get an 530 error response, then you probably connected on port 587
> and need to send an StartTLS command, before you can log in.
> 
> If you get an 538 error response, then you probably didn't connect on port
> 465, but need an (implicit) SSL connection, before you can log in.
> 
> Hope that helps,
> 
> Andreas
>
Sabrina FobesRe: EMAIL PROBLEM
on Thu, 11 Aug 2022 21:18:05 -0400
Ok working I was sent incorrect data QWSIRYT users!!!


On 8/8/22 9:30 AM, James Loughner wrote:
> Thanks Andreas This example did use 465 but the same errors seem to be 
> 586. Hmmm since PW is base 64 maybe I need to trim it before sending?????
> 
> Jim
> 
> 
> On 8/7/22 6:29 PM, Andreas Gehrs-Pahl wrote:
>> James,
>>
>> Your program and log file don't show which port you are using. I assume
>> that you use port 465, which is the "implicit" TLS port, which creates an
>> (implicit) SSL connection before any text is sent. The log file indicates
>> no problems with connecting on the chosen port, though, even if it was 
>> 587
>> (which would require a StartTLS command, but that isn't in the log file).
>>
>> The SMTP server sends a 334 response challenge to your "AUTH LOGIN" 
>> request:
>>
>>> Info: Send: AUTH LOGIN
>>> Info: Recv: 334 VXNlcm5hbWU6 (==> "Username:" Base64 encoded)
>>
>> Your program then sends the user name: 
>> office@colebrooknewsandsentinel.com
>>
>>> Info: Send: b2ZmaWNlQGNvbGVicm9va25ld3NhbmRzZW50aW5lbC5jb20=
>>
>> Then the server asks for the password:
>>> Info: Recv: 334 UGFzc3dvcmQ6 (==> "Password:" Base64 encoded)
>>
>> to which your program responds with sending the (Base64 encoded) 
>> password:
>>
>>> Info: Send: dDVqc3ZhRyRuRjQ1biZo (==> "t5jsvaG$nF45n&h" Base64 encoded)
>>
>> The server then responds with the 535 error message "Authentication 
>> failed",
>> because the username and/or password are incorrect.
>>
>>> Info: Recv: 535 Authentication failed
>>
>> You should verify that the username and password are correct (and 
>> don't post
>> them on an open forum, like this one, even if they are Base64 encoded).
>>
>> If you get an 530 error response, then you probably connected on port 587
>> and need to send an StartTLS command, before you can log in.
>>
>> If you get an 538 error response, then you probably didn't connect on 
>> port
>> 465, but need an (implicit) SSL connection, before you can log in.
>>
>> Hope that helps,
>>
>> Andreas
>>
>