Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was tried lots of code to send email to user after 2 days of registration but i was not solved this issue.

What I have tried:

I am trying to get registration date from table and compare it with current date and send auto email after 2 days to users.
anyone have an idea to send email after 2 days to user in c# mvc.
Posted
Updated 10-Nov-20 19:52pm
v2

Would recommend use a separate process (mostly a windows service) to do such periodic work. (not the web application you are using)

Service will periodically check your database for users and the date they registered. If it's more than 2 days, it will send an email.

For windows service:
Sending Emails Automatically and periodically Using C#[^]
Automatically send emails daily at specific time using Windows Service in C# and VB.Net[^]

In case you still want to use ASP.NET project to email, then you can use timer in the webproject running on a server. Take queues from:
ASP.NET MVC 5 - SMTP Email Notification[^]
Sending Mail in Background with ASP.NET MVC — Hangfire Documentation[^]


In case you are stuck with getting data from DB, you would need to share the SQL query where you are unable to get the data.
 
Share this answer
 
There are two elements to a solution:
First, add a DATETIME column to your Users table to say "needs an email on" and set it to the current date plus two days.

Then write a little checking app, which gets all the users from the DB where that field is less than the current DateTime. That app sends the email.

Most hosting services and operating systems provide scheduling, where you can set an app to run every day, or every hour - use the latter and run your app once an hour. It runs, gets it's list, sends them an email, and shuts down again.

Exactly how you make it work depends on your hosting systems: if you are self hosting then Windows provides the Task Scheduler (Linux does something similar). If you are hosted then look at the website panel and it should be fairly obvious.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900