@EliottENAnnoucement Sure thing, i’m very sorry I didn’t see this earlier!
So you wanna find an api,
I’m using the one found here (sign up and use the free “subscription”): SendGrid API Documentation (sendgrid) | RapidAPI
Then back on roblox studio’s we’re going to make a remote event (in ReplicatedStorage
) called SendFeedback
, and a Script
inside of ServerScriptService
, time for the code break down:
First things first we need to get the HttpService
so we can make API requests:
local HttpService = game:GetService("HttpService") -- Get the http service so we can make calls to the api
Next we wanna get replicated storage and grab the remote event:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SendFeedbackEvent = ReplicatedStorage.SendFeedback
Now into the variables for our API, we first need the API URL and the Headers, both of these will be found on you Rapid Api thing (where I sent you the API)
local API_URL = "https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send"
local Headers = {
['X-RapidAPI-Key'] = "Your Key Here",
['X-RapidAPI-Host'] = "Your Host Here"
}
Now we initialize a function, take in a parameter for the Title of the Email and for the actual feedback, then we’ll initialize our payloads:
local function SendFeedback(Player, Title, Feedback)
local payload = {
["personalizations"] = {
{
["to"] = {{["email"] = "yourrecievingemail@here.com"}}, -- Add the email to recieve the emails
["subject"] = Title -- The Title of the email the user sent (using the parameter of the remote event)
}
},
["from"] = {["email"] = "yoursendingemail@here.com"}, -- Add your sending email here
["content"] = {
{
["type"] = "text/plain",
["value"] = Feedback -- This is the feedback the user gave (taking it from the remote event parameter)
}
}
}
The payloads are our data, this is all the stuff we are sending, but we can’t use that data yet, we first need to encode it in a JSON format using JSONEncode
:
local data = HttpService:JSONEncode(payload)
Finally we want to Send our API request and exit the function:
HttpService:PostAsync(API_URL, data, Enum.HttpContentType.ApplicationJson, false, Headers)
end
Last thing to do for this is connect our remote event to that function:
SendFeedbackEvent.OnServerEvent:Connect(SendFeedback)
Full code for that:
local HttpService = game:GetService("HttpService") -- Get the http service so we can make calls to the api
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SendFeedbackEvent = ReplicatedStorage.SendFeedback
local API_URL = "https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send"
local Headers = {
['X-RapidAPI-Key'] = "Your Key Here", -- Replace
['X-RapidAPI-Host'] = "Your Host Here" -- Replace
}
local function SendFeedback(Player, Title, Feedback)
local payload = {
["personalizations"] = {
{
["to"] = {{["email"] = "yourrecievingemail@here.com"}}, -- Add the email to recieve the emails
["subject"] = Title -- The Title of the email the user sent (using the parameter of the remote event)
}
},
["from"] = {["email"] = "yoursendingemail@here.com"}, -- Add your sending email here
["content"] = {
{
["type"] = "text/plain",
["value"] = Feedback -- This is the feedback the user gave (taking it from the remote event parameter)
}
}
}
local data = HttpService:JSONEncode(payload)
HttpService:PostAsync(API_URL, data, Enum.HttpContentType.ApplicationJson, false, Headers)
end
SendFeedbackEvent.OnServerEvent:Connect(SendFeedback)
Alright, now onto the UI, for this i’m doing a simple UI but you can do what you want. Here’s what you need though, 2 text boxes (one for the email title, one for the feedback) and a send button.
In the send button you will have a local script that looks something like this (just change the paths to the labels and that stuff)
local RS = game:GetService('ReplicatedStorage')
local Event = RS.SendFeedback
local FeedbackFrame = script.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
Event:FireServer(FeedbackFrame.Title.Text, FeedbackFrame.Feedback.Text)
end)
And BOOOM! Working feedback email system.
MAKE SURE TO ENABLE ACESS TO HTTP SERVICES IN SETTINGS
Some Recomendations:
- Add a delay, only let a user send 1 email like every few hours or so (so you don’t spam and they don’t use the full rate)
That’s all really, hope this helped!