Page 1 of 2

E-mail with 4.0

Posted: Thu Mar 09, 2006 4:18 pm
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!

Posted: Thu Mar 09, 2006 6:22 pm
by tomijan
Hi!
Look an http://people.freenet.de/gnozal/
2 libraries for PB4 : POP3 and SMTP can resolve your problem
tom

Posted: Thu Mar 09, 2006 6:31 pm
by Inf0Byt3
Thank you very much tomijan!

Posted: Fri Mar 10, 2006 3:46 am
by mskuma
Seems like the links to the PB4 version are broken (due to in-progress?).

Posted: Fri Mar 10, 2006 8:50 am
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.

Re: E-mail with 4.0

Posted: Fri Mar 10, 2006 1:50 pm
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).

Posted: Fri Mar 10, 2006 9:14 pm
by Inf0Byt3
Very nice! Works perfectly :D
Thanks.

Posted: Sat Mar 11, 2006 11:49 am
by PB
FYI: Just edited it to make it smaller, and removed a global variable. See above.

Posted: Sat Mar 11, 2006 11:52 am
by Inf0Byt3
8) Thanks!

Posted: Sat Mar 11, 2006 11:57 am
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.

Posted: Mon Mar 20, 2006 7:10 am
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?

Posted: Mon Mar 20, 2006 7:40 am
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. :(

Posted: Mon Mar 20, 2006 7:11 pm
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?

Posted: Mon Mar 20, 2006 7:58 pm
by srod
Works well for me. Nice code.

Posted: Mon Mar 20, 2006 8:06 pm
by Inf0Byt3
However, attachements would be a nice feature too. (I need it to send infections found by my antispyware project)