Advertisement
DOGGYWOOF

Untitled

Nov 23rd, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. -- Email Client (client.lua)
  2. local modem = peripheral.find("modem") -- Auto-detect modem
  3. if not modem then
  4. print("No modem found!")
  5. return
  6. end
  7. rednet.open("front") -- Open the modem on the "front" side
  8.  
  9. -- Function to send email to the server
  10. local function sendEmail()
  11. print("Enter recipient ID (Server ID should be 'server'):")
  12. local recipientID = read()
  13. if recipientID ~= "server" then
  14. print("Error: Invalid recipient ID")
  15. return
  16. end
  17. print("Enter email subject:")
  18. local subject = read()
  19. print("Enter email message:")
  20. local message = read()
  21.  
  22. -- Ensure valid recipient ID, subject, and message
  23. if recipientID == "" or subject == "" or message == "" then
  24. print("All fields must be filled out!")
  25. return
  26. end
  27.  
  28. -- Debugging: Check what is being sent
  29. print("Sending email to server...")
  30. print("Recipient ID: " .. recipientID)
  31. print("Subject: " .. subject)
  32. print("Message: " .. message)
  33.  
  34. -- Send email to server via Rednet
  35. rednet.send(recipientID, { "sendEmail", os.getComputerID(), subject, message })
  36. print("Email sent to " .. recipientID)
  37. end
  38.  
  39. -- Function to retrieve emails from the server
  40. local function retrieveEmails()
  41. print("Retrieving emails...")
  42. rednet.send("server", { "retrieveEmails", os.getComputerID() })
  43.  
  44. -- Wait for response from server
  45. while true do
  46. local senderID, msg = rednet.receive() -- Receive message from the server
  47. if msg[1] == "emailContent" then
  48. print("Emails retrieved:")
  49. print(msg[2])
  50. break
  51. end
  52. end
  53. end
  54.  
  55. -- Main menu to either send or retrieve emails
  56. while true do
  57. print("1. Send Email")
  58. print("2. Retrieve Emails")
  59. local choice = tonumber(read())
  60.  
  61. if choice == 1 then
  62. sendEmail()
  63. elseif choice == 2 then
  64. retrieveEmails()
  65. else
  66. print("Invalid choice")
  67. end
  68. end
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement