PureSMTP library : mail & attachments (AUTH supported)

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

Moderator: gnozal

loulou
User
User
Posts: 38
Joined: Tue Dec 08, 2009 7:42 am

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by loulou »

Can you developed a version in which html mail will be possible ?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by gnozal »

loulou wrote:Can you developed a version in which html mail will be possible ?
I do not know any SMTP command to handle the outbox.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by DoubleDutch »

It may be handy to have a function to send RAW commands to the SMTP server and get the RAW reply (on the current PureSMTP connection)? Possible the same for the PurePop3 library too?
(I wish Fred would add this to his FTP and Mail libraries)
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:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by gnozal »

DoubleDutch wrote:It may be handy to have a function to send RAW commands to the SMTP server and get the RAW reply (on the current PureSMTP connection)? Possible the same for the PurePop3 library too?
Sending some user defined text is not a problem.
But how to handle the server answer ? It maybe a short text, megabytes of data, or an error message.
This is handled by a message loop in PureSMTP.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by DoubleDutch »

I see what you mean, maybe specify a timeout in the send command - all data captured in an expanding memory buffer until that time has passed since last data reply? It could default to 1/2 second? The memory address would be the return parameter?

eg:

Code: Select all

reply=PureSMTP_RawSend(command$[,timeout])
if reply
.
.
.
   FreeMemory(reply)
endif
This way other users can add commands that may be missing (they may only be on certain servers and not part of the official SMTP spec?) and submit them to you for 'offical' inclusion (if you like)?
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:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by gnozal »

I will try to think of something usable.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by C64 »

Is PureSMTP_SetContentType() meant to remember its setting after PureSMTP_CloseSMTPConnection() is called? Because once I set the content type to "text/html" and send an email, and close the connection, the next email sent is also "text/html" instead of the default of "text/plain". I would've thought the default would be used whenever PureSMTP_OpenSMTPConnection() is called?

Basically, I currently have to do this with my program:

Code: Select all

;monospaced is a global variable depending on how I want to send.

If PureSMTP_OpenSMTPConnection(...)=#PureSMTP_Ok
  If monospaced=1
    PureSMTP_SetContentType("text/plain; charset=iso-8859-1")
  Else
    PureSMTP_SetContentType("text/html; charset=iso-8859-1")
  EndIf
  result=PureSMTP_SendMail(...)
  PureSMTP_CloseSMTPConnection()
EndIf
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by gnozal »

C64 wrote:Is PureSMTP_SetContentType() meant to remember its setting after PureSMTP_CloseSMTPConnection() is called?
Yes, like PureSMTP_SetXMailer() and PureSMTP_SetBoundary().
Set the value to "" to reset to default value.

I have updated the help file.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by C64 »

Thank you. Another question (for you or any lurkers): I can easily send image attachments with PureSMTP, but what about sending an HTML email with the image embedded? I know I'd have to compose the email body with HTML tags, but I'm unsure of how I'd get the image data in there. Base64 I assume, with boundaries? Am I close? Can someone post some theory so I can do the practice? Thanks again.
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by C64 »

Found a bug (I think) in PureSMTP today, when trying to use PureSMTP_AddHeader(). Reproducible code follows (without my data). Example taken from the PureSMTP help file. Using PureBasic 4.51 and the latest PureSMTP library, on XP (32-bit). Turning the Purifier on gives a different address in the error message, rather than 0. Changing the addresses in MailTo and MailFrom doesn't fix the error.

Code: Select all

Line: 12 - Invalid memory access. (write error at address 0)

Code: Select all

MySMTPServer.s = "MySMTPServer"
MySMTPPort.l = 25
If PureSMTP_OpenSMTPConnection(MySMTPServer, MySMTPPort) = #PureSMTP_Ok
  Debug PureSMTP_GetLastServerMessage()
  MailTo.s = "whoever@you.want"
  MailFrom.s = "root@127.0.0.1"
  Subject.s = "Test"
  MsgBody.s = "Testing PureSMTP"
  Attachments.s = ""
  ;Username.s = "TEST"
  ;Password.s = "TEST"
  PureSMTP_AddHeader("X-MSMail-Priority", "High")
  ; sending mail
  Status.l = PureSMTP_SendMail(MailTo, MailFrom, Subject, MsgBody)
  If Status = #PureSMTP_Ok
    Debug "Message : sent"
    Debug "Status = " + Str(Status)
  Else
    Debug "Message : something went wrong !"
    Debug "Status = " + Str(Status)
    Debug PureSMTP_GetLastServerMessage()
  EndIf
  PureSMTP_CloseSMTPConnection()
Else
  Debug "OpenSMTPConnection failed"
  Debug PureSMTP_GetLastServerMessage()
EndIf
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by gnozal »

C64 wrote:Found a bug (I think) in PureSMTP today, when trying to use PureSMTP_AddHeader(). Reproducible code follows (without my data). Example taken from the PureSMTP help file. Using PureBasic 4.51 and the latest PureSMTP library, on XP (32-bit). Turning the Purifier on gives a different address in the error message, rather than 0. Changing the addresses in MailTo and MailFrom doesn't fix the error.
Sorry, I can't reproduce the issue : the mail is sent with high priority as expected.
No debugger error.
No purifier alert.
No crash.
PB4.51 / XP sp3 x86
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by C64 »

I noticed I also get the exact same crash with just one line in the IDE like this (compile/run it):

Code: Select all

PureSMTP_AddHeader("X-MSMail-Priority", "High")
What does this do on your PC?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by gnozal »

C64 wrote:I noticed I also get the exact same crash with just one line in the IDE like this (compile/run it):

Code: Select all

PureSMTP_AddHeader("X-MSMail-Priority", "High")
What does this do on your PC?
Nothing.
Note : this function just adds an element to a linked list in the library.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by C64 »

With the Purifier enabled, the single line compiles and runs fine. Disabled, it crashes. Just musing out loud.

[Update] Just noticed that if I enable "Create Threadsafe Executable", the single lines causes this:

Code: Select all

---------------------------
PureBasic - Linker error
---------------------------
POLINK: error: Unresolved external symbol '_PB_StringBasePosition'.
POLINK: fatal error: 1 unresolved external(s).
---------------------------
OK
---------------------------
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PureSMTP library : mail & attachments (AUTH supported)

Post by DoubleDutch »

You should do a reinstall of purebasic and the extra libs - it works fine on mine.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply