Posted: Fri Apr 07, 2006 5:53 pm
				
				I use this lib all the time, thanks Gnozal!!
			http://www.purebasic.com
https://www.purebasic.fr/english/
No.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?
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
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")  
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")
Glad it works.stnien wrote:Hi gnozal,
Yes, it can work. You are a PureBasic Expert. Thank you!
Works here with or without space.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.
Yes, I will change this.GeoTrail wrote: Only seems to work with the senders email addy.
Did you check PureSMTP_SetXMailer() ?GeoTrail wrote:One more thing, is it possible to let the programmer change this line?
Received: from PureSMTP
Code: Select all
PureSMTP_SetXMailer(XMailer.s) ; Set X-Mailer [Default is "PureSMTP"]I don't know php. Why do you need this ?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?
Code: Select all
PureSMTP_SetContentType(ContentType.s) ; Set content type [Default is "text/plain; charset=iso-8859-1"]