PureSMTP library : mail & attachments (AUTH supported)

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi Gnozal,

Which AUTH versions does your library actual use? I have a SMTP server that denies the e-mails with the following error:

Error code 504 5.7.4 Unrecognized authentication type.

Do you only support AUTH LOGIN or do you support CRAM-MD5, too? It seems to me that some mailservers only support the MD5 method (http://en.wikipedia.org/wiki/SMTP-AUTH).

Kukulkan
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Kukulkan wrote:Hi Gnozal,

Which AUTH versions does your library actual use? I have a SMTP server that denies the e-mails with the following error:

Error code 504 5.7.4 Unrecognized authentication type.

Do you only support AUTH LOGIN or do you support CRAM-MD5, too? It seems to me that some mailservers only support the MD5 method (http://en.wikipedia.org/wiki/SMTP-AUTH).

Kukulkan
Currently only AUTH LOGIN.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I get Invalid mem access (read error at address 0) in line 19 here:

Code: Select all

MySMTPServer.s="mailhost.terra.es"
MySMTPPort.l=25
If PureSMTP_OpenSMTPConnection(MySMTPServer.s,MySMTPPort.l)=#PureSMTP_Ok
  Debug PureSMTP_GetLastServerMessage()
  MailFrom.s="some@terra.es"
  MailTo.s="any@hotmail.com"
  Subject.s="Test (with attachments)"
  MsgBody.s="Testing PureSMTP"
  UserName.s="some.terra.es"
  Password.s="blahblah"
  HeaderAddon.s="Time: "+FormatDate("%yyyy/%mm/%dd %hh:%ii:%ss",Date())
  ; file attachements
  File1.s="D:\AL\new\PureSMTP_.zip":If FileSize(File1)<=0:File1="":EndIf
  File2.s="D:\AL\new\fmts.txt":If FileSize(File2)<=0:File2="":EndIf
  Separator.s="":If File1.s And File2.s:Separator=";":EndIf
  Attachments.s=File1.s+Separator.s+File2.s
  ; sending mail
  Debug Attachments
  Status.l = PureSMTP_SendMail(MailTo.s,MailFrom.s,Subject.s,MsgBody.s,Attachments.s,UserName.s,Password.s,HeaderAddon.s)
  If Status = #PureSMTP_Ok
    Debug "Message 1 : sent"
    Debug "Status = " + Str(Status)
    Debug PureSMTP_GetLastServerMessage()
  Else
    Debug "Message 1 : something went wrong !"
    Debug "Status = " + Str(Status)
    Debug PureSMTP_GetLastServerMessage()
  EndIf
  PureSMTP_CloseSMTPConnection()
Else
  Debug "OpenSMTPConnection failed"
  Debug PureSMTP_GetLastServerMessage()
EndIf
:cry:
PB4.10B4.
Notice that without attachments it works nice!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Psychophanta wrote:I get Invalid mem access (read error at address 0) in line 19 here: ... :cry:
PB4.10B4.
Notice that without attachments it works nice!
Do you have Vista ... ?
PureSMTP seems to crash on Vista if base64 encoding is used (auth login or attachments).
I have tested the code with Freak's ValidatePBHeap() function : no problem reported.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

PureSMTP seems to crash on Vista if base64 encoding is used (auth login or attachments).
This does happen, no understandable reason why though - very strange.

Could you implement some kind of callback scheme for the encoding/decoding (pure_pop3 would need it too) - so we can try get to the bottom of the problem?

This feature may be useful in any event?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:
PureSMTP seems to crash on Vista if base64 encoding is used (auth login or attachments).
This does happen, no understandable reason why though - very strange.

Could you implement some kind of callback scheme for the encoding/decoding (pure_pop3 would need it too) - so we can try get to the bottom of the problem?

This feature may be useful in any event?
Here a test EXE : http://freenet-homepage.de/gnozal/PureSMTP_VISTA.zip
1. It uses an external DLL for the base64 encoding (you can replace it with your own code)
2. The EXE is stuffed with ValidatePBHeap() calls.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I've been doing some tests and the latest version of your lib works (so does the vista test program).

But if you enter the wrong password both the lib crashes and your vista test app crashes, here is the message from the vista test app:
PureSMTP has crashed [Error = C00000005]
'An attemped read or write to/from an address to which that process isn't allowed'
Module: C:\Purebasic400\Compilers\PB_EditorOutput2.pb ; Line 434
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Sorry for the delay but no Vista, but Windows XP SP2 here.

I forgot: please add also SSL auth to be able to send messages using gmail for example :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:I've been doing some tests and the latest version of your lib works (so does the vista test program).
That's weird ... I didn't change anything (compiled 25 APR 2007) ! Maybe Vista has changed ?
DoubleDutch wrote:But if you enter the wrong password both the lib crashes and your vista test app crashes
Not here with WinNT4, it says 'Authentication unsuccesful'.
Line 434 is the base64 DLL function call ... Could you test with your own base64 code in the DLL ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Psychophanta wrote:Sorry for the delay but no Vista, but Windows XP SP2 here.
I just tested your code (with other settings / files), no problem here.
Psychophanta wrote:I forgot: please add also SSL auth to be able to send messages using gmail for example :?
I don't know the SSL/TLS protocol, and many apps use a third party DLL from www.OpenSSL.org , so it doesn't look that easy ...
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Looks like it may be either a PureBasic bug or a bug with Vista?

Code: Select all

; Base64.DLL
Global Result.s
Procedure.s _PureSMTP_Base64Encode(strText.s)
  Protected *B64EncodeBufferA, *B64EncodeBufferB, OutputBufferLength.l, InputBufferLength.l
  InputBufferLength = Len(strText)
  OutputBufferLength = InputBufferLength * 2 ; et pas * 1.33 comme dans le manuel !
  If OutputBufferLength < 64
    OutputBufferLength = 64
  EndIf 
  *B64EncodeBufferA = AllocateMemory(InputBufferLength)
  *B64EncodeBufferB = AllocateMemory(OutputBufferLength)
  CompilerIf #PB_Compiler_Unicode ;>
    PokeS(*B64EncodeBufferA, strText, InputBufferLength, #PB_Ascii)
  CompilerElse ;=
    PokeS(*B64EncodeBufferA, strText)
  CompilerEndIf ;<
  Base64Encoder(*B64EncodeBufferA, InputBufferLength, *B64EncodeBufferB, OutputBufferLength)
  Result = PeekS(*B64EncodeBufferB)
  FreeMemory(*B64EncodeBufferA)
  FreeMemory(*B64EncodeBufferB) ; <-- crashes here!!!
  ProcedureReturn Result
EndProcedure
;test$=_PureSMTP_Base64Encode("ab1234567") ; <- works
test$=_PureSMTP_Base64Encode("ab123456")  ; <- crashes on Vista
Debug(test$)
Very strange, anyhow I've posted it to bugs.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

The bug is:

Code: Select all

*B64EncodeBufferA = AllocateMemory(InputBufferLength)
it should be...

Code: Select all

*B64EncodeBufferA = AllocateMemory(InputBufferLength+1)
Because PokeS writes a trailing zero at the end. Vista memory protection must be more "picky" than XP and below.
An optional length parameter (in bytes) can be specified that defines the length of the string itself, a zero will still be placed in memory after the poked string (ie. specifying 6 will write 7 bytes, 6 for the string, and the last byte will be zero).



(Thanks to "jpd" for helping me figure it out.)

Edit: ABBKlaus suggests +2 for unicode...
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:The bug is:

Code: Select all

*B64EncodeBufferA = AllocateMemory(InputBufferLength)
it should be...

Code: Select all

*B64EncodeBufferA = AllocateMemory(InputBufferLength+1)
Because PokeS writes a trailing zero at the end. Vista memory protection must be more "picky" than XP and below.
That makes sense.
I will change it. The stupid thing is, I did it right in other portions of the code :oops:

Code: Select all

*B64EncodeBufferA = AllocateMemory(InputBufferLength + 2)
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Thanks. As soon as you put an update online I'll check it on Vista for you. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Update (Both libs)

Changes :
- fixed (very) stupid bug in Base64 encoding function.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply