PureSMTP library : mail & attachments (AUTH supported)

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

Moderator: gnozal

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

Post by gnozal »

I could reproduce the PureSMTP_SetXMailer() crash on Win98SE.
It seems to be some strange PB4/Tailbite memory management issue, because :
- the same code works with PB4 on NT based systems
- the same code works with PB3.94 on NT based systems AND Win95 based systems
I think I found the problem : the string variable initialization in PureSMTP_Init() when the library is loaded.
If I avoid this, there is no crash anymore.
Changes :

Code: Select all

ProcedureDLL PureSMTP_Init()
  ...
  ; PureSMTP_ContentType = "text/plain; charset=" + #g + "iso-8859-1" + #g
  ; PureSMTP_XMailer = "PureSMTP"
  ; PureSMTP_Boundary = "PureSMTP_"
  ...
EndProcedure
;
Procedure.l PureSMTP_SendMailEx(MailTo.s, MailFrom.s, Subject.s, MsgBody.s, Attachments.s, UserName.s, Password.s, HeaderAddon.s)
  ...
  ;
  If PureSMTP_XMailer = ""
    PureSMTP_XMailer = "PureSMTP"
  EndIf
  If PureSMTP_ContentType = ""
    PureSMTP_ContentType = "text/plain; charset=" + #g + "iso-8859-1" + #g
  EndIf
  If PureSMTP_Boundary = ""
    PureSMTP_Boundary = "PureSMTP_"
  EndIf
  ;
  ...
EndProcedure
Could you please test http://freenet-homepage.de/gnozal/PureSMTP_BETA.zip (ANSI PureSMTP beta lib) under Win9x/Me ?
The users with NT based systems too please. If it works, I will update the PB4 library.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

DoubleDutch:
I have sent you the files, as requested, but in the light of Gnozal's last post it is likely that any analysis of the files will now be redundant. Many thanks for offering your help, it is really appreciated.

Gnozal:
The Beta library seems to solve the crashout problems under Windows ME. Deep joy! Thank you.

In summary, these now work correctly:
PureSMTP_SetContentType()
PureSMTP_SetXMailer()
PureSMTP_SetTimeOut() - though I think this has always worked

I have not yet tested these:
PureSMTP_SetBoundary()
PureSMTP_AddHeader()
PureSMTP_ClearHeader()


I have two requests:

1. Minor request: Would it be possible for either the X-Mailer to default to <null> rather than "PureSMTP" or for there to be some [other] way of supressing the X-Mailer line?

2. Major request: I need a way of discovering whether a previously created SMTP connection still exists or whether it been unexpectedly lost so that I need to create another. This is to cover the situation where I am automatically sending an email at regular intervals and it seems a waste of resources to create and close the SMTP connection for every email. So I would like to stay connected for the duration of sending all the emails (perhaps over a period of an hour or more), but have a capability of detecting that the connection has unexpectedly become lost before sending my next email.
[Or would opening a new connection do nothing if the previous connection was still open? This may be an indirect way of resolving my request.]
Anthony Jordan
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

akj wrote:The Beta library seems to solve the crashout problems under Windows ME. Deep joy! Thank you.
Good news.
akj wrote:1. Minor request: Would it be possible for either the X-Mailer to default to <null> rather than "PureSMTP" or for there to be some [other] way of supressing the X-Mailer line?
Actually no. What's the problem ?
akj wrote:2. Major request: I need a way of discovering whether a previously created SMTP connection still exists or whether it been unexpectedly lost so that I need to create another. This is to cover the situation where I am automatically sending an email at regular intervals and it seems a waste of resources to create and close the SMTP connection for every email. So I would like to stay connected for the duration of sending all the emails (perhaps over a period of an hour or more), but have a capability of detecting that the connection has unexpectedly become lost before sending my next email.
[Or would opening a new connection do nothing if the previous connection was still open? This may be an indirect way of resolving my request.]
Why don't you just use the sequence PureSMTP_OpenSMTPConnection() / send mail / PureSMTP_CloseSMTPConnection() each time you send mail ?
Anyway, if you call PureSMTP_OpenSMTPConnection() without having closed the previous connection with PureSMTP_CloseSMTPConnection(), PureSMTP will just keep using current connection.
If the server has disconnected and you try to send some mail, you will get an error, probably #PureSMTP_BadResponse (check PureSMTP_GetLastServerMessage())
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 »

Update (PB4 version only)

Changes :

- fixed a strange PB4/Tailbite memory management issue under Win9x/Me
(crashed functions PureSMTP_ContentType() PureSMTP_XMailer() PureSMTP_Boundary())
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

Gnozal wrote:
If you call PureSMTP_OpenSMTPConnection() without having closed the previous connection with PureSMTP_CloseSMTPConnection(), PureSMTP will just keep using current connection
This solves my main request. Thank you.
Is there any chance of you adding that important fact to your documentation for PureSMTP_OpenSMTPConnection() and, if appropriate, for PureSMTP_OpenPOP3ThenSMTPConnection().
Anthony Jordan
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

akj wrote:Is there any chance of you adding that important fact to your documentation for PureSMTP_OpenSMTPConnection() and, if appropriate, for PureSMTP_OpenPOP3ThenSMTPConnection().
I will.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

could someone supply a valid link to PureSMTP, all the ones I've followed timeout (including the one from PureArea)

Thanks
Matt
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Try a different browser!
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

I've tried both the evil IE and the not-so-evil Mozilla, neither want to work - my guess is that gnozal's site is down for whatever reason.

does anyone have this lib (and are prepared to host it?)
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I tried downloading yesterday and 2 secs ago and it worked fine here.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

citystate wrote:I've tried both the evil IE and the not-so-evil Mozilla, neither want to work - my guess is that gnozal's site is down for whatever reason.
The site is not down, and I have no problems downloading. Maybe a firewall / antivirus problem ?
Anyway, you can also try PureArea (may not be the latest version though) : http://www.purearea.net/pb/english/userlibs.php
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

thanks - I'm still getting the problem though (well, not with the 3.91 version, but definitely with the 4.x one). Doesn't appear to be a firewall problem. :?

oh well - thanks for the effort guys, I'm sure the lib would have been perfect :) guess I'll have to remake the wheel :P

ahh - nevermind, I managed to find it here --> http://www.purearea.net/pb/download/use ... eSMTP_.zip
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi gnozal,

I currently use your library on a PB3.94 project. It works fine, but some people ask for using SSL/TLS for sending e-mails (especially those who are using gmail.com). Is it possible to send and receive e-mails using SSL/TLS? Actualy, only sending is important for me.

I don't know which API's you are using, but maybe it is possible to use InternetOpenUrl_() with the #INTERNET_FLAG_SECURE flag to connect to the server?

regards,

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,
I currently use your library on a PB3.94 project. It works fine, but some people ask for using SSL/TLS for sending e-mails (especially those who are using gmail.com). Is it possible to send and receive e-mails using SSL/TLS? Actualy, only sending is important for me.
I don't know which API's you are using, but maybe it is possible to use InternetOpenUrl_() with the #INTERNET_FLAG_SECURE flag to connect to the server?
I don't use WinAPI, only the purebasic network library functions.
And I don't know the SSL/TLS protocol (I don't know if it's even possible without API).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

gnozal wrote:I don't use WinAPI, only the purebasic network library functions.
And I don't know the SSL/TLS protocol (I don't know if it's even possible without API).
The SSL protocol is well known and documented all over the web, but it is a huge bunch of work to implement this by yourself. The windows-API provides all functions needed to connect using SSL if you are using InternetOpen_(), InternetOpenUrl_() and InternetReadFile_() to manage your connections (instead of the PB functions). Bad news is, that this will only work using windows.

Kukulkan
Post Reply