Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Email Client (client.lua)
- local modem = peripheral.find("modem") -- Auto-detect modem
- if not modem then
- print("No modem found!")
- return
- end
- rednet.open("front") -- Open the modem on the "front" side
- -- Function to send email to the server
- local function sendEmail()
- print("Enter recipient ID (Server ID should be 'server'):")
- local recipientID = read()
- if recipientID ~= "server" then
- print("Error: Invalid recipient ID")
- return
- end
- print("Enter email subject:")
- local subject = read()
- print("Enter email message:")
- local message = read()
- -- Ensure valid recipient ID, subject, and message
- if recipientID == "" or subject == "" or message == "" then
- print("All fields must be filled out!")
- return
- end
- -- Debugging: Check what is being sent
- print("Sending email to server...")
- print("Recipient ID: " .. recipientID)
- print("Subject: " .. subject)
- print("Message: " .. message)
- -- Send email to server via Rednet
- rednet.send(recipientID, { "sendEmail", os.getComputerID(), subject, message })
- print("Email sent to " .. recipientID)
- end
- -- Function to retrieve emails from the server
- local function retrieveEmails()
- print("Retrieving emails...")
- rednet.send("server", { "retrieveEmails", os.getComputerID() })
- -- Wait for response from server
- while true do
- local senderID, msg = rednet.receive() -- Receive message from the server
- if msg[1] == "emailContent" then
- print("Emails retrieved:")
- print(msg[2])
- break
- end
- end
- end
- -- Main menu to either send or retrieve emails
- while true do
- print("1. Send Email")
- print("2. Retrieve Emails")
- local choice = tonumber(read())
- if choice == 1 then
- sendEmail()
- elseif choice == 2 then
- retrieveEmails()
- else
- print("Invalid choice")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement