PureSMTP library : mail & attachments (AUTH supported)

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

Moderator: gnozal

User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Post by doctorized »

gnozal wrote:I guess PureSMTP_OpenSMTPConnection() fails because you have a corporate firewall / proxy at work, and unfortunately Purebasic network functions don't support proxies.
I have the same issue at work.
I am a teacher, so we have a computer that is connected directly to the internet through the greek school network. AVG 8.5 internet security is installed and even if I disable the firewall component, PureSMTP_OpenSMTPConnection() fails. I am thinking this: there is a server of the greek school network, that lies somewhere in Athens, and I think that this server may block the connections to servers other than itself. I do not know if this is possible. This server is definitely intercalated between me and the web because some sites are not accessable and a message saying that the page cannot be viewed because of the content, so I think that it may be responsible for my problem.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Post by doctorized »

gnozal wrote:I guess PureSMTP_OpenSMTPConnection() fails because you have a corporate firewall / proxy at work, and unfortunately Purebasic network functions don't support proxies.
I have the same issue at work.
I was right! I tried to send through the school server and the mail sent. Can I do something to be able to send via gmx or any other server that I have account? I need a way to bypass the stupid mail.att.sch.gr server.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

doctorized wrote:I was right! I tried to send through the school server and the mail sent. Can I do something to be able to send via gmx or any other server that I have account? I need a way to bypass the stupid mail.att.sch.gr server.
Did you try to use PureSMTP_OpenSMTPConnection() with the gmx server ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Post by doctorized »

gnozal wrote:Did you try to use PureSMTP_OpenSMTPConnection() with the gmx server ?
Yes, the first server that I used was gmx (mail.gmx.com). I found a list with about 350 servers (http://www.e-eeasy.com/SMTPServerList.aspx), the code connected with none of them. Only the school server connects correctly.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

doctorized wrote:
gnozal wrote:Did you try to use PureSMTP_OpenSMTPConnection() with the gmx server ?
Yes, the first server that I used was gmx (mail.gmx.com). I found a list with about 350 servers (http://www.e-eeasy.com/SMTPServerList.aspx), the code connected with none of them. Only the school server connects correctly.
I am sorry, but I don't know how to 'bypass' a firewall in Purebasic.
Maybe HTTP tunneling (like Yourfreedom) would work, but it's a bit overkill ...
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.3x version only)

Changes :
- enhanced function PureSMTP_SendMail() : added memory attachments.
  You may specify a memory bank instead of a filename.
    . syntax : use "mem:{Filename}:{*InputBuffer}:{InputBufferLength}" instead of "{Path+Filename}"
    . example :

Code: Select all

...
      If ReadFile(666, "c:\PureBasic430\Program\test.zip")
        InMemAttachmentLen = Lof(666)
        *InMemAttachment = AllocateMemory(InMemAttachmentLen)
        If *InMemAttachment
          ReadData(666, *InMemAttachment, InMemAttachmentLen)
          Attachments.s = "mem:test.zip:" + Str(*InMemAttachment) +":" +  Str(InMemAttachmentLen)
        EndIf
        CloseFile(666)
      EndIf
...
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re:

Post by doctorized »

gnozal wrote:only x86 libs, as I don't have a 64bits OS.
I have 64bit XP PRO, Windows 7 x64 and PB x64 4.30. I can help you make x64 lib.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Char(10) lost after file transfer with PureSMTP

Post by doctorized »

I use Gnozal's PureSMTP to send mails with attachments.
I have some codes like this one:

Code: Select all

CreateFile(0,"c:\text.txt")
WriteStringN(0, FormatDate("%dd/%mm/%yyyy - %hh:%ii:%ss",Date()))
WriteString(0,"Text saved")
CloseFile(0)

If PureSMTP_OpenSMTPConnection("your smtp server", 25) = #PureSMTP_Ok
	MailTo.s = "the taker address"
	MailFrom.s = "your email address"
	UserName.s = "your id"
	Password.s = "your password"
	Subject.s ="Hi!"
	MsgBody.s = "file attached"
	Attachments.s = "c:\text.txt"
	
	Status.l = PureSMTP_SendMail(MailTo, MailFrom, Subject, MsgBody, Attachments, UserName, Password) 
	PureSMTP_CloseSMTPConnection()
	If Status = #PureSMTP_Ok
		Debug "file sent"
	Else 
		Debug "failed"
	EndIf
Else
	Debug "connection failed"
EndIf
When I downloaded the file, I noticed that the enter key, chr(10) + chr(13), is not normally present. Chr(10) is missing after the date, only chr(13) is present.
The original file on my hard disk has chr(10) but the downloaded one doesn't. If I try to sent bigger files then chr(10) is present. Can somebody explain me why, please?
Mr Coder
User
User
Posts: 54
Joined: Tue Apr 13, 2010 8:02 am

Re: Char(10) lost after file transfer with PureSMTP

Post by Mr Coder »

It's probably your mail client saving the file, that's causing the problem. When I run your code, the saved file is exactly the same as what the code originally created, except for a new added CRLF at the end of it. So, my client (Outlook) adds a single new CRLF when saving the attachment. Other than that, the file attachment is 100% the same, byte-for-byte (confirmed with a hex editor), as it was created. Don't forget that Outlook strips line breaks in emails, so that may be doing something to the attachment too.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Char(10) lost after file transfer with PureSMTP

Post by doctorized »

Mr Coder wrote:Don't forget that Outlook strips line breaks in emails, so that may be doing something to the attachment too.
I am not using any client. I send the mail with PB and then I download the attachment from the provider's web page with Firefox.
Mr Coder
User
User
Posts: 54
Joined: Tue Apr 13, 2010 8:02 am

Re: Char(10) lost after file transfer with PureSMTP

Post by Mr Coder »

Try the same code with PureBasic's mail sending, and see if it works. That way we'll know if PureSMTP has a bug or not. I doubt it does, though. Sounds like the mail server or downloading action is modifying the text file on the fly. Try also mailing a binary file (an executable?) with PureSMTP, and if that comes through okay then PureSMTP is definitely not the problem.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Char(10) lost after file transfer with PureSMTP

Post by doctorized »

Mr Coder wrote:Try also mailing a binary file (an executable?) with PureSMTP
I sent a dll file and the downloaded file has the same CRC32 code with the original one, so PureSMTP
works fine. I did one more test and found out this: if the taker is gmx.com or yahoo.com then chr(10)
is lost after downloading, but when the taker is hotmail.com then the file comes back ok. I did it with both
IE and firefox so the downloading action is not responsible for this. Why do yahoo and gmx f*ck attachments?
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

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

Post by AndyMK »

POLINK error _PB_StringBasePosition using PB4.50 with threadsafe switched on
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 »

AndyMK wrote:POLINK error _PB_StringBasePosition using PB4.50 with threadsafe switched on
Did you enable the 'UserLibThreadSafe' subsystem ?
PureSMTP.chm (How to use this library in unicode and/or thread-safe mode) wrote:This library exists in several versions :
- the standard version, located in %Purebasic%\PureLibraries\UserLibraries\ ;
- the thread-safe version, located in %Purebasic%\SubSystems\UserLibThreadSafe\PureLibraries\ .
- the unicode version, located in %Purebasic%\SubSystems\UserLibUnicode\PureLibraries\ .
- the unicode + thread-safe version, located in %Purebasic%\SubSystems\UserLibunicodeThreadSafe\PureLibraries\ .
In order to use this library in thread-safe mode (compiler option /THREAD), you have to enable the subsystem 'UserLibThreadSafe'
in the PB IDE, or add '/SUBSYSTEM UserLibThreadSafe' to the PBCompiler arguments. In jaPBe, do nothing : it will automatically
enable the 'UserLibThreadSafe' subsystem to use the threadsafe versions of the installed userlibraries.
It's the same logic for unicode and unicode + thread-safe modes.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

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

Post by AndyMK »

Thanks, didn't see that one.
Post Reply