Page 5 of 25

Posted: Fri Apr 07, 2006 5:53 pm
by Beach
I use this lib all the time, thanks Gnozal!!

could run in unicode mode?

Posted: Sat Nov 25, 2006 7:36 am
by stnien
Thanks Gnozal ! I like your Pure_SMTP library. But I have a trouble in using this library. It seems don't work in unicode mode?

Re: could run in unicode mode?

Posted: Sat Nov 25, 2006 8:58 am
by gnozal
stnien wrote:Thanks Gnozal ! I like your Pure_SMTP library. But I have a trouble in using this library. It seems don't work in unicode mode?
No.
Well, I can compile the lib in unicode mode (works), but the SMTP server I tested doesn't understand unicode, so it doesn't work. I guess I would have to translate all the strings to ASCII before sending them and translate the strings received to UNICODE ...

BTW, I have just updated PureSMTP for PB4 with a threadsafe version.

Posted: Sat Nov 25, 2006 1:43 pm
by stnien
Hi Gnozal,

I've try to run the code with unicode mode..

Code: Select all

If InitNetwork()
    MailID=OpenNetworkConnection("myserver",25)
    *a = AllocateMemory(9999)
    res = ReceiveNetworkData(MailID, *a, 9999)
    response.s = ""
    For i = 0 To res - 1
    	response + Chr(PeekB(*a+i))
    Next
    Debug response
    
    CloseNetworkConnection(MailID)
EndIf
When I run it, I can get "220 xxxxxx" (ps: SMTP server's banner). So I think SMTP can accept unicode string, but the response data isn't unicode string. Therefore maybe have to do a translation after receive response data.

Posted: Sun Nov 26, 2006 6:34 am
by stnien
Sorry, I try again and I confirm that SMTP can't accept unicode string. Whatever send to SMTP server or receive from SMTP server, all of these strings have to use non unicode.

SMTP send mail with unicode mode

Posted: Mon Nov 27, 2006 3:12 pm
by stnien
Okay, I try to the code send mail with unicode mode and it works.

Code: Select all

Global MailID

Procedure MailDataSend(msg$)
	Debug "Command: "+msg$
	*cmd = AllocateMemory(9999)
	For i = 1 To Len(msg$)
		asc = Asc(Mid(msg$, i, 1))
		PokeB(*cmd+i-1, asc)
	Next
	
	SendNetworkData(MailID, *cmd, Len(msg$))
EndProcedure

Procedure.s MailResponse()
	a$=Space(9999)
	res = ReceiveNetworkData(MailID,@a$,9999)
	response.s = ""
    For i = 0 To res - 1
       response + Chr(PeekB(@a$+i))
    Next
	
	Debug response
	ProcedureReturn Left(response,3)
EndProcedure

Procedure MailSend(ms_server$,ms_port$,ms_recipient$,ms_subject$,ms_body$,ms_from$)
	If InitNetwork()
		MailID=OpenNetworkConnection(ms_server$,Val(ms_port$))
		If MailID
			If MailResponse()="220"
				MailDataSend("HELO Mailer"+#CRLF$)
				If MailResponse()="250"
					MailDataSend("MAIL FROM: <"+ms_from$+">"+#CRLF$)
					If MailResponse()="250"
						MailDataSend("RCPT TO: <"+ms_recipient$+">"+#CRLF$)
						If MailResponse()="250"
							MailDataSend("DATA"+#CRLF$)
							If MailResponse()="354"
								MailDataSend("Date: "+#CRLF$)
								MailDataSend("From: "+ms_from$+#CRLF$)
								MailDataSend("To: "+ms_recipient$+#CRLF$)
								MailDataSend("Subject: "+ms_subject$+#CRLF$)
								MailDataSend(ms_body$) : MailDataSend(""+#CRLF$) : MailDataSend("."+#CRLF$)
								If MailResponse()="250" : MailDataSend("QUIT"+#CRLF$) : result=1 : EndIf
							EndIf
						EndIf
					EndIf
				EndIf
			EndIf
			CloseNetworkConnection(MailID)
		EndIf
	EndIf
	ProcedureReturn result
EndProcedure

MailSend("mail.isp.com.au","25","to@address.com","SubjectGoesHere","BodyGoesHere","from@address.com")  
PS: The original code is post in http://www.purebasic.fr/english/viewtop ... a8d9bbc68a
and programmer is PB.

Re: SMTP send mail with unicode mode

Posted: Mon Nov 27, 2006 3:56 pm
by gnozal
Something like this should also work (using PokeS/PeekS) [not tested, I don't have PB right here] :
stnien wrote:Okay, I try to the code send mail with unicode mode and it works.

Code: Select all

Global MailID

Procedure MailDataSend(msg$)
	Debug "Command: "+msg$
	*cmd = AllocateMemory(9999)
;	For i = 1 To Len(msg$)
;		asc = Asc(Mid(msg$, i, 1))
;		PokeB(*cmd+i-1, asc)
;	Next
         PokeS(*cmd, msg$, Len(msg$) , #PB_Ascii)
	
	SendNetworkData(MailID, *cmd, Len(msg$))
EndProcedure

Procedure.s MailResponse()
	a$=Space(9999)
	res = ReceiveNetworkData(MailID,@a$,9999)
	response.s = ""
;    For i = 0 To res - 1
;       response + Chr(PeekB(@a$+i))
;    Next
    response =  PeekS(@a$, res , #PB_Ascii)
	
	Debug response
	ProcedureReturn Left(response,3)
EndProcedure

Procedure MailSend(ms_server$,ms_port$,ms_recipient$,ms_subject$,ms_body$,ms_from$)
	If InitNetwork()
		MailID=OpenNetworkConnection(ms_server$,Val(ms_port$))
		If MailID
			If MailResponse()="220"
				MailDataSend("HELO Mailer"+#CRLF$)
				If MailResponse()="250"
					MailDataSend("MAIL FROM: <"+ms_from$+">"+#CRLF$)
					If MailResponse()="250"
						MailDataSend("RCPT TO: <"+ms_recipient$+">"+#CRLF$)
						If MailResponse()="250"
							MailDataSend("DATA"+#CRLF$)
							If MailResponse()="354"
								MailDataSend("Date: "+#CRLF$)
								MailDataSend("From: "+ms_from$+#CRLF$)
								MailDataSend("To: "+ms_recipient$+#CRLF$)
								MailDataSend("Subject: "+ms_subject$+#CRLF$)
								MailDataSend(ms_body$) : MailDataSend(""+#CRLF$) : MailDataSend("."+#CRLF$)
								If MailResponse()="250" : MailDataSend("QUIT"+#CRLF$) : result=1 : EndIf
							EndIf
						EndIf
					EndIf
				EndIf
			EndIf
			CloseNetworkConnection(MailID)
		EndIf
	EndIf
	ProcedureReturn result
EndProcedure

MailSend("mail.isp.com.au","25","to@address.com","SubjectGoesHere","BodyGoesHere","from@address.com")  

Posted: Tue Nov 28, 2006 3:53 am
by stnien
Hi gnozal,

Yes, it can work. You are a PureBasic Expert. Thank you! :D

Posted: Tue Nov 28, 2006 8:35 am
by gnozal
stnien wrote:Hi gnozal,

Yes, it can work. You are a PureBasic Expert. Thank you! :D
Glad it works.
I will try to update the lib when I have some time.

Posted: Tue Nov 28, 2006 2:28 pm
by gnozal
Update (PB4 version only)

Added unicode version.

I lost some time on base64 / unicode issues but should work now.

Posted: Thu Nov 30, 2006 8:52 am
by gnozal
GeoTrail wrote:When I enter the from address with name like this: My name <email@addy.com> it doesn't send the name. But if I remove the space like this My name<email@addy.com> it works. But I can't get it to send the name of the recipient.
Works here with or without space.
Could you post a code example ?
GeoTrail wrote: Only seems to work with the senders email addy.
Yes, I will change this.


Could you test this beta lib (ANSI / PB4) : http://people.freenet.de/gnozal/PureSMTP_BETA.zip ?
It should now work for the recipient.

Posted: Thu Nov 30, 2006 2:12 pm
by GeoTrail
Thanks for you reply gnozal.
I'm testing it now. Just waiting for that darn server to receive the mail. Sooo sloowww hehehe

Posted: Thu Nov 30, 2006 5:47 pm
by GeoTrail
That works great gnozal, thanks alot for the update.
One more thing, is it possible to let the programmer change this line?

Received: from PureSMTP

Would also be great to be able to edit more settings too, like Content-Transfer-Encoding: 7bit

Would that be possible? kinda like with php sendmail?

Posted: Fri Dec 01, 2006 8:39 am
by gnozal
GeoTrail wrote:One more thing, is it possible to let the programmer change this line?
Received: from PureSMTP
Did you check PureSMTP_SetXMailer() ?

Code: Select all

PureSMTP_SetXMailer(XMailer.s) ; Set X-Mailer [Default is "PureSMTP"]
GeoTrail wrote: Would also be great to be able to edit more settings too, like Content-Transfer-Encoding: 7bit
Would that be possible? kinda like with php sendmail?
I don't know php. Why do you need this ?
I send "Content-Transfer-Encoding: 7bit" for text and "Content-Transfer-Encoding: base64" for binary attachments.
Note that you can set the content type with PureSMTP_SetContentType().

Code: Select all

PureSMTP_SetContentType(ContentType.s) ; Set content type [Default is "text/plain; charset=iso-8859-1"]

Posted: Fri Dec 01, 2006 10:01 am
by gnozal
Update (both versions)

Changes :
- "My name <email@addy.com>" syntax can now also be used for recipient.