PureSMTP library : mail & attachments (AUTH supported)
Moderator: gnozal
could run in unicode mode?
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?
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: could run in unicode mode?
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?
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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Hi Gnozal,
I've try to run the code with unicode mode..
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.
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
SMTP send mail with unicode mode
Okay, I try to the code send mail with unicode mode and it works.
PS: The original code is post in http://www.purebasic.fr/english/viewtop ... a8d9bbc68a
and programmer is PB.
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")
and programmer is PB.
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: SMTP send mail with unicode mode
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")
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Glad it works.stnien wrote:Hi gnozal,
Yes, it can work. You are a PureBasic Expert. Thank you!
I will try to update the lib when I have some time.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Update (PB4 version only)
Added unicode version.
I lost some time on base64 / unicode issues but should work now.
Added unicode version.
I lost some time on base64 / unicode issues but should work now.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
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.
Could you post a code example ?
Yes, I will change this.GeoTrail wrote: Only seems to work with the senders email addy.
Could you test this beta lib (ANSI / PB4) : http://people.freenet.de/gnozal/PureSMTP_BETA.zip ?
It should now work for the recipient.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
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?
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?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
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?
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"]
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Update (both versions)
Changes :
- "My name <email@addy.com>" syntax can now also be used for recipient.
Changes :
- "My name <email@addy.com>" syntax can now also be used for recipient.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).