Hi All

I have a table (contactDetails) in my database (Sql express) with username,password, email, contactNo, bySMS and byEmail columns. I have 2 radiobuttons in my application smsRB and EmailRB, when the user registers he must select either smsRb or EmailRB. if smsRB is selected, a "Y" is inserted under bySMS column in that user's record, else if EmailRB is selected a "Y" is inserted under byEmail column in that user's record. I have another webform where I upload files in a database:

my challenge is: Everytime I upload a file I want my application to send an SMS notification to all the user who chose the smsRB when they registered and send an email notification to all the users who chose EmailRB.

Please help me achieve this task. let me know if its not clear. (using C# 2005)
Thanks

Dani AI

Generated

Short note: 's approach of selecting only the users who opted in and then iterating to send notifications is the simplest correct solution for a small number of recipients, and it explains why saw success. 's suggestion to use carrier SMTP gateways can work for ad‑hoc texts, but it is brittle for bulk or production use (carrier formats vary, gateways can block mass mail, and deliverability is harder to manage).

If this will run more than occasionally, avoid sending messages directly inside the upload request. Instead, queue the notifications and let a background worker or service process the queue. That gives durability, retries, throttling and logging without risking web timeouts. A minimal notification queue table might include: Id, UserId, Method (SMS/Email), Destination (phone/email), Payload, Status, Attempts, LastError, CreatedAt, SentAt. Insert rows at upload time and let a dedicated worker pick them up, send, update status and retry with exponential backoff.

Operational tips: validate and normalize phone numbers (use E.164), validate emails before sending, store opt‑in flags consistently (boolean or small enum), and always use parameterized queries to avoid injection. For SMS prefer a modern API provider (Twilio is a common choice) rather than relying on carrier email gateways; for email use a transactional provider or a robust library. See Twilio SMS docs for APIs and explore libraries like MailKit for sending email reliably.

Finally, if users may want both channels, normalize the schema (a contact_preferences table or a single preference field) rather than two ad hoc columns. Index the preference column for fast selection, log sends for auditing, and implement unsubscribe/error handling so repeated attempts do not annoy users or get the system blacklisted.

Recommended Answers

All 5 Replies

just do a search on google for how to send email via c#, you should find tons of samples

as for the SMS, it kind of depends
easiest way would be to collect phone number and carrier for each user and send it via SMTP
[phonenumber]@[carrierSMTPgateway]
again, you should be able to get a listing of the bigger carriers gateways via a google search

if you don't want to send text messages via SMTP like that, it costs more and/or you need some hardware

Thanks for the reply

what I need is one C# statement for this:

foreach emailAdd where byEmail = Y

emailAdd and byEmail are columns in a Database table.

if I can get this statement I am sure i can work it out from there. I dont need the email/sms code.

ok, then are you loading the data from the database into a datatable object?
an array of datarow objects?
dataset object?

Get the data from the database with a new statement:
select byEmail from ContactDetails where byEmail = 'Y'

Then in c#:
foreach(DataRow row in YourDataSet.Tables["YourTable"].Rows)
sendYourEmailTo( row["byEmail"].ToString() );

Or if you already have the dataset loaded...
DataRow[] emailers = YourDataSet.Tables["YourTable"].Select("byEmail = 'Y'");
foreach(DataRow row in emailers)
sendYourEmailTo( row["byEmail"].ToString() );

Or if using an SqlDataReader...
SqlConnection conn = new SqlConnection( YourConnectionString );
SqlCommand cmd = new SqlCommand("select byEmail from ContactDetails where byEmail = 'Y'",conn);
conn.Open();
SqlDataReader row = cmd.ExecuteReader();
while (row.Read())
{
sendYourEmailTo( row["byEmail"].ToString() );
}
conn.Close();

// Jerry
PS: Just typed off the top of my head, so verify syntax before use.

Thanks a lot Jerry it work :icon_smile:

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.