; VM2 mail code snippets ; As it stands, this works as a test/demo program on the Micro-Robotics ; office network, where the VM2 has an email account named "vm2" on the server. ; To use on your network, all the user names, passwords and IP addresses will have ; to be changed ; ; The code illustrates: ; * sending email to any destination ; * reading and deleting any number of messages from a POP3 mailbox ; * extracting header values such as "Subject" and "Sender" in a received message ; Converted for Venom 2 To init ; create ethernet interface using DHCP - we don't need it's handle. New Ethernet ; "thor.localnet" is our local server, which can handle both outgoing (SMTP) mail ; and incoming POP3 mailboxes. ; In many cases the POP3 and SMTP servers will be different. Make pop3 POP3Mailbox("thor.localnet") Make smtp SMTPSender("thor.localnet", "vm2.localnet") End To main send_test_message Print "waiting for message to be processed", CR Wait 2000 Print "trying to receive message", CR receive_messages End ; in the code that follows, we give the VM2's email recipient and sender ; an email address of vm2@thor.localnet ; VM2 sends a fixed test message to itself ; (this relies on the VM2 having a user account on server thor.localnet) To send_test_message AutoDestruct Local msg := New Buffer(Char) Print To msg, "Hello!", CR, "This is a test message", CR send_email_to("VM2 test <vm2@thor.localnet>", "test message", msg) End ; send a message to anyone ; dest, subject and msg are buffers or strings To send_email_to(dest, subject, msg) Local rc Print "sending to ", dest, CR rc := smtp.Send("VM2 test <vm2@thor.localnet>", dest, subject, "", msg) If rc = 0 Print "msg sent OK", CR Else Print "message sending failed, error code ", rc:1, CR End ; receives, displays and deletes all messages in mailbox ; ; The vm2 has a user account for POP3 mail with username "vm2" and password "vm2" ; Normally you would use something a bit more cryptic! To receive_messages Local n n := pop3.Open("vm2", "vm2") ; username and password If n > 0 [ Repeat n ; positive n = number of messages in mailbox [ Print "From: ", pop3.(Index, "from"), CR, "Subject: ", pop3.(Index, "subject"), CR, "====", CR ; display the message contents ; you could use PRINT TO to store message in a buffer or file Print pop3:Index, CR, "====", CR, CR pop3.Remove(Index) ; marke for deletion now we've read it ] pop3.Close ; server will now remove deleted messages ] Else If n= 0 [ Print "no messages",CR pop3.Close ] Else ; negative n means error Print "pop3 error code ", n,CR End