Hi all, i have a scenario in which there are two subscribed users (to database) in my web app.......now if one of it wants to send a message (just like mail but not sms) to another without using any email account...... but with the help of that website and some magical method is it possible, if yes than what would be the magical method could be used to acheive this......I am a new bie therefore asking such questions???

Dani AI

Generated

Your DB-backed approach is the right pattern for in-app messaging. outlined a simple flow and is correct that this is how many sites handle internal messages. Below are compact, practical improvements and gotchas to make the feature secure, reliable and easy to scale.

Suggested minimal schema (SQL Server):

CREATE TABLE Notifications (
  NotificationId INT IDENTITY(1,1) PRIMARY KEY,
  SenderUserId INT NOT NULL,
  RecipientUserId INT NOT NULL,
  Subject NVARCHAR(200) NULL,
  Body NVARCHAR(MAX) NOT NULL,
  IsRead BIT NOT NULL DEFAULT (0),
  CreatedAt DATETIME2 NOT NULL DEFAULT (GETUTCDATE()),
  Link NVARCHAR(500) NULL,
  AttachmentPath NVARCHAR(500) NULL,
  IsDeleted BIT NOT NULL DEFAULT (0)
);

CREATE INDEX IX_Notifications_Recipient_IsRead ON Notifications(RecipientUserId, IsRead, CreatedAt);

Small C# insert example (use parameterized commands or an ORM):

using(var conn = new SqlConnection(connString))
using(var cmd = conn.CreateCommand())
{
  conn.Open();
  cmd.CommandText = "INSERT INTO Notifications (SenderUserId, RecipientUserId, Subject, Body) VALUES (@s,@r,@sub,@body)";
  cmd.Parameters.AddWithValue("@s", senderId);
  cmd.Parameters.AddWithValue("@r", recipientId);
  cmd.Parameters.AddWithValue("@sub", (object)subject ?? DBNull.Value);
  cmd.Parameters.AddWithValue("@body", body);
  cmd.ExecuteNonQuery();
}

Key implementation notes and cautions:

  • Always use the server-side user ID from your auth system when inserting or selecting messages; don’t trust client-supplied usernames/IDs.
  • Encode or sanitize Body on output to prevent XSS (HttpUtility.HtmlEncode or a vetted sanitizer).
  • Enforce authorization on reads (WHERE RecipientUserId=@currentUserId).
  • Use paging and the index above for large inboxes. Archive or purge old rows to control table growth.
  • For near-real-time delivery use SignalR (push) or short AJAX polling; checking only at login is simple but not live.
  • Store attachments in blob storage or file system and save paths in DB; wrap file operations and DB writes in a transaction-like workflow to avoid orphans.

Troubleshooting tips: check indexes if queries are slow, verify you’re encoding output when odd characters appear, and log operations that change read/delete state so you can diagnose race conditions.

Recommended Answers

All 3 Replies

Do you want them to send an actual email (i.e. the message appears in their email account) or send a message to the user the next time they access your app (message sent and held by your software)?

commented: thnaks +1

Dear hericles i don't want to send an actual mail what i want is.......
1. First of all i have registered two users say one is admin and the second one is an employee.....

2. Admin wants to send a notification to his employee of any kind, so what he do is to just select the employee's username from drop down list in my webpage and send him a message....and that message will stored in the database notification-table.............

3. On the other hand (employee's end) when he signed in, i will make a query something like that "select * from notification-table where username is equal to the current log-in username" if it has any notifications regarding to him than it was shown in a gridview, and when he clicks the view buton in the gridview his message will be shown to him....That's it...

NOW KINDLY TELL ME THAT WHETHER THE ABOVE PROPOSED SOLUTION IS LOGICAL OR NOT??????/

Its perfectly logical. It is how most sites handle their internal messages. There is no need to over think it. You can include all the functionality of emails (bcc, cc, attachments, replies, etc) as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.