Quickly send an email :
Question to TSQL.APP
I need to input an email-address and then a mail with the text hello from tsql.app should be sent to that address.
Response from TSQL.APP
I'll help you create a simple modal interface where you can input an email address and send a test email.
Here's the code to accomplish this:
-- Declare variables
DECLARE @EmailAddress NVARCHAR(256);
DECLARE @SendButton NVARCHAR(MAX);
-- Synchronize values with the client
EXEC sp_api_modal_get_value @name='@EmailAddress', @value=@EmailAddress OUT;
EXEC sp_api_modal_get_value @name='@SendButton', @value=@SendButton OUT;
-- Display title
EXEC sp_api_modal_text @text='Send Test Email', @class='h2';
-- Create input field for email address
EXEC sp_api_modal_input
@name='@EmailAddress',
@value=@EmailAddress OUT,
@type='email',
@placeholder='Enter email address';
-- Add send button
EXEC sp_api_modal_button
@name='@SendButton',
@value='Send Email',
@valueout=@SendButton OUT,
@class='btn-primary';
-- If send button is clicked and email is provided
IF @SendButton IS NOT NULL AND @EmailAddress IS NOT NULL
BEGIN
-- Send the email
EXEC sp_api_email
@to = @EmailAddress,
@subject = 'Test Email from TSQL.APP',
@body = 'Hello from TSQL.APP!';
-- Show success message
EXEC sp_api_toast @text='Email sent successfully!', @class='success';
-- Clear the modal
EXEC sp_api_modal_clear;
RETURN;
END
This code will:
- Create a modal with an email input field
- Add a "Send Email" button
When the button is clicked, it will:
- Send an email to the provided address
- Show a success toast notification
- Close the modal
You can copy this code and use it in a TSQL.APP action. When you run it, you'll see a form where you can enter an email address and send the test email.