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 »

Use the PureSMTP_AddHeader() block only one time before PureSMTP_SendMail(). The second time you are sending the headers twice. The server may not like it.

Or use PureSMTP_ClearHeader(), like this :

Code: Select all

...
If PureSMTP_OpenSMTPConnection(MySMTPServer, MySMTPPort) = #PureSMTP_Ok 
            PureSMTP_SetXMailer("Testemail") 
            PureSMTP_SetContentType("text/html; charset=iso-8859-1") 

            PureSMTP_ClearHeader() ; <=============
            PureSMTP_AddHeader("X-MSMail-Priority", "Normal") 
            PureSMTP_AddHeader("Reply-To", "geotrail@gmail.com") 
             
            Head$ = "<html><head><meta http-equiv="+Chr(34)+"Content-Type"+Chr(34)+" content="+Chr(34)+"text/html; charset=UTF-8"+Chr(34)+"><title>Gmail</title></head><body>" 
            Footer$ = "</body></html>" 
            Message$ + Head$ + Msg$ + Footer$ 
             
            Status = PureSMTP_SendMail(Ricipient$, "Robert Olsen <geotrail@start.no>", Subject$, Message$, "") 
            If Status = #PureSMTP_Ok
...
Maybe this solves your problem.
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 Both versions

Changes :
- new function PureSMTP_AddHeader(Header.s, String.s) ; Set additional header strings.
- new function PureSMTP_ClearHeader() ; Clears the additional the header strings.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

That didn't work, but adding this PureSMTP_CloseSMTPConnection() did hehehe :lol: I added it to the second code but not the first :shock:

Thank you so much for your hard work gnozal. I think I have all your libs for PB4 and use them frequently, specially love PureRESIZE, that makes my life so much easier ;)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Small bug (missing 'feature'?): PureSMTP won't let you send a file attachment that has zero length.

Outlook and TheBat, do...

PurePop3 however will accept and create a zero length file attachment no problem. :)

Also, could there be an option to change the boundary 'pre-text', it seems set to:

PureSMTP_[boundary here]
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:Small bug (missing 'feature'?): PureSMTP won't let you send a file attachment that has zero length.
It's a feature.

Code: Select all

InputBufferLength.l = Lof(Stream) ; Attachment length
*InputBuffer = AllocateMemory(InputBufferLength)
If *InputBuffer
  ; Encode attachment
Why would you do that ?
DoubleDutch wrote:Also, could there be an option to change the boundary 'pre-text', it seems set to : PureSMTP_[boundary here]
Will see ...
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 wouldn't normally want to send a file of zero length either. My 'automated' system tried... ;)

But, other email systems seem to allow it and PurePop3 will accept and create a zero length file. So I guessed it may have been overlooked with PureSMTP. Thought you may not have noticed.
Also, could there be an option to change the boundary 'pre-text', it seems set to : PureSMTP_[boundary here]
Will see ...
:)
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 :
- new function PureSMTP_SetBoundary()
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 (again for the very fast updating) :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hello, first time i use it. it's very useful.

on my dev computer it's ok - every time i send a mail.

but on our server i get this message :
354 Enter mail, end "." on a line by itself
i can see here for example that error 354 is :
http://www.greenend.org.uk/rjk/2000/05/ ... plies.html
354 : Start mail input; end with <CRLF>.<CRLF>

But i don't really understand the problem.

I need some help/experience to point the problem. :idea: :?:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:hello, first time i use it. it's very useful.
on my dev computer it's ok - every time i send a mail.
but on our server i get this message :
354 Enter mail, end "." on a line by itself
The SMTP server sends '354' when it is ready to receive the mail text.
A communication example :
<CONNECT>
RECEIVE : 220 VSMAIL.myserver.local Microsoft ESMTP MAIL Service, Version: 6.0.3790.1830 ready at Thu, 18 Jan 2007 16:53:37 +0100

SEND : HELO PureSMTP
RECEIVE : 250 VSMAIL.myserver.local Hello [xxx.xxx.xxx.xxx]

SEND : MAIL FROM: <Gnozal@myserver.fr>
RECEIVE : 250 2.1.0 Gnozal@myserver.fr....Sender OK

SEND : RCPT TO: <Gnozal@myserver.fr>
RECEIVE : 250 2.1.5 Gnozal@myserver.fr

SEND : DATA
RECEIVE : 354 Start mail input; end with <CRLF>.<CRLF>

SEND : From: Gnozal <Gnozal@myserver.fr>
SEND : To: <Gnozal@myserver.fr>
SEND : Date: 05 May 2005 12:00:00

etc...
I don't understand when you get this message ? Does PureSMTP_SendMail() fail and you get this message with PureSMTP_GetLastServerMessage() ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

yes i get this message from your last message function.

also - and it is important - the mail is send correctly (i can check it and i really received it).

and i receive #PureSMTP_ServerTimeOut = -6 as a result of the send mail function.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

That's strange ...
If the mail is sent correctly and you get the time out error, then the following seems to happen :
1. PureSMTP dialogs with server
2. Server sends 'Start Message' (354)
3. PureSMTP sends the mail text
4. PureSMTP sends 'End of message' (CRLF.CRLF)
5. PureSMTP waits for 'Closing transmission' message (221) from the server
6. PureSMTP doesn't get any answer and quits with #PureSMTP_ServerTimeOut error (and last server message is 354)
Why does the server not answer, I don't know ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Who fix the TimeOut value ?

the server or PureSMTP ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

after some test, it works successfully about 2 times on 3.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:Who fix the TimeOut value ?
the server or PureSMTP ?
PureSMTP (default is 5 s, you can change it with PureSMTP_SetTimeOut())
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply