E-mail with 4.0

Just starting out? Need help? Post your questions and find answers here.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

E-mail with 4.0

Post by Inf0Byt3 »

Hello. Does anyone have some code to send e-mail from PB 4.0? I've searched the forums but haven't found much results.
Thanks in advance!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
tomijan
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 1:32 pm

Post by tomijan »

Hi!
Look an http://people.freenet.de/gnozal/
2 libraries for PB4 : POP3 and SMTP can resolve your problem
tom
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Thank you very much tomijan!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Seems like the links to the PB4 version are broken (due to in-progress?).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

mskuma wrote:Seems like the links to the PB4 version are broken (due to in-progress?).
Yes, they will be released when PB 4 final and Tailbite for PB4 are released.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: E-mail with 4.0

Post by PB »

> Does anyone have some code to send e-mail from PB 4.0?

Here's something I posted ages ago that I updated for v4.00, but it doesn't
support attachments. But for quick sending of e-mails, it works great! :)
Not mine but I cleaned it up and streamlined it into a neat little code block.
My original post was here: http://www.purebasic.fr/english/viewtopic.php?t=3805

> I've searched the forums but haven't found much results.

There are some links in the Coding Questions FAQ. ;)

Code: Select all

Global MailID
Procedure MailDataSend(msg$)
  SendNetworkData(MailID,@msg$,Len(msg$))
EndProcedure
Procedure.s MailResponse()
  a$=Space(9999) : ReceiveNetworkData(MailID,@a$,9999)
  ProcedureReturn Left(a$,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")
(Edited to make it even smaller, and removed a global variable).
Last edited by PB on Mon Mar 20, 2006 9:22 pm, edited 3 times in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Very nice! Works perfectly :D
Thanks.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

FYI: Just edited it to make it smaller, and removed a global variable. See above.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

8) Thanks!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

What I like about this procedure is you don't need to rely on third-party libs,
and it also doesn't make firewalls prompt you (such as Kerio). It's nice code.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

Seems to work great EXCEPT my body text isn't coming through in the email ... any ideas?

Also, you wouldn't happen to have similarly straightforward sample code for POP3, would ya?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Seems to work great EXCEPT my body text isn't coming through in the
> email ... any ideas?

Don't know, works great here... what sort of body text are you sending?
Can you post a snippet to show what fails? I've yet to have it fail on me.

> Also, you wouldn't happen to have similarly straightforward sample code
> for POP3, would ya?

Not yet. :(
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

PB wrote:... Can you post a snippet to show what fails? I've yet to have it fail on me.
I'm using the exact code you posted here, except with my ISP's smtp server and my email addresses.
Nothing is really failing, the email is successfully sent and delivered, just when the email is delivered, there's no body ...
I'm using Thunderbird, is this working for everyone else using Thunderbird?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Works well for me. Nice code.
I may look like a mule, but I'm not a complete ass.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

However, attachements would be a nice feature too. (I need it to send infections found by my antispyware project)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply