I am writing a program in C# using Windows Forms and I am stuck at this part.
When any user logs in to the program for the first time in any given week, an email should be sent to all users who have a task (the task will be assigned by an admin). If a user has no tasks, he/she should not receive an email. When the second user logs in for that week, emails should not be sent.
I mean when the any first user of the program logging in, the emails will be send for all users who has tasks (to remind them to do the task). The problem is I do not want one user to receive too many duplicate emails.I already have the code for sending the emails, but I need a way to handle the rest of the process. I have researched and I saw that Windows Services might be an option.
Is there another way to do this?
public int OutLook_Send_Email_To_User(string user_Email, string email_Subject, string email_Content)
{
try
{
Outlook.Application outApp = new Outlook.Application();
Outlook.MailItem outMsg = (Outlook.MailItem)outApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipient outTo = null;
outApp = new Outlook.Application();
outMsg = (Outlook.MailItem)outApp.CreateItem(Outlook.OlItemType.olMailItem);
outTo = (Outlook.Recipient)outMsg.Recipients.Add(user_Email);
outTo.Type = (int)Outlook.OlMailRecipientType.olTo;
outTo.Resolve();
outMsg.Subject = email_Subject;
outMsg.HTMLBody = email_Content;
outMsg.Save();
outMsg.Send();
outTo = null;
outMsg = null;
outApp = null;
return 0;
}
catch (Exception ex)
{
return -1;
}
}