Email Trigger
-
How to create an email trigger in asp.net when the user logs in to his account everytime and his inbox will show an email notifying that something has been updated in the database? Something like an email notification. ^.^ frossie
-
not sure i understand requirements, but can you have your login routine send an email? or have i completely missed the point? g00fy
Hey. Actually no, that's y i'm asking if anyone can help by providing an example of the source codes. What i meant was, if the user login and click on the login button, he/she will be logged into his/her account but at the same time, there will be a notification email sent to their email to inform them of the latest updates to the database. frossie
-
Hey. Actually no, that's y i'm asking if anyone can help by providing an example of the source codes. What i meant was, if the user login and click on the login button, he/she will be logged into his/her account but at the same time, there will be a notification email sent to their email to inform them of the latest updates to the database. frossie
does this help for .NET 2.0 .NET 1.1 is similar just google MailMessage + .NET 1
string server = "mail.server.com"; string to = "123@123.com"; string from = "123@123.com"; string subject = "Using the SMTP client."; string body = @"Message Body"; MailMessage message = new MailMessage(from, to, subject, body); SmtpClient client = new SmtpClient(server); client.Timeout = 100; // change this to set username and password if required by SMTP server client.Credentials = CredentialCache.DefaultNetworkCredentials; client.Send(message);
-
does this help for .NET 2.0 .NET 1.1 is similar just google MailMessage + .NET 1
string server = "mail.server.com"; string to = "123@123.com"; string from = "123@123.com"; string subject = "Using the SMTP client."; string body = @"Message Body"; MailMessage message = new MailMessage(from, to, subject, body); SmtpClient client = new SmtpClient(server); client.Timeout = 100; // change this to set username and password if required by SMTP server client.Credentials = CredentialCache.DefaultNetworkCredentials; client.Send(message);
-
So by inserting this code, an automated email will be sent everytime the user logs in to his account? But i don't see where the place to insert the default message into the message body. Can u guide me more into it? frossie
the
body
var is the email body. just change it to suit your needs. then insert this code into a function and call the function from your login function. it may be best to thread the mail function as the login routine will wait for the mail function to return if it is not threaded, and login may 'appear' to hang to the user. something like this adhog should do it, the code below is threaded and the Mutex() ensures that only one object can access this routine at any one time, to overcome any concurrency issues.using System.Threading;
private AutoResetEvent m_WriteEvent = new AutoResetEvent(false);
private Mutex m_Mutex = new Mutex();public bool Login()
{
// your login function logic is here
.
.
.
ThreadPool.QueueUserWorkItem(SendLoginEmail, this.m_WriteEvent);
m_WriteEvent.WaitOne();
}private void SendLoginEmail(object state)
{
m_Mutex.WaitOne();string server = "mail.server.com";
string to = "123@123.com";
string from = "123@123.com";
string subject = "Using the SMTP client.";
string body = @"Message Body";MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient(server);
client.Timeout = 100;// change this to set username and password if required by SMTP server
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);m_Mutex.ReleaseMutex();
((AutoResetEvent)state).Set();
} -
the
body
var is the email body. just change it to suit your needs. then insert this code into a function and call the function from your login function. it may be best to thread the mail function as the login routine will wait for the mail function to return if it is not threaded, and login may 'appear' to hang to the user. something like this adhog should do it, the code below is threaded and the Mutex() ensures that only one object can access this routine at any one time, to overcome any concurrency issues.using System.Threading;
private AutoResetEvent m_WriteEvent = new AutoResetEvent(false);
private Mutex m_Mutex = new Mutex();public bool Login()
{
// your login function logic is here
.
.
.
ThreadPool.QueueUserWorkItem(SendLoginEmail, this.m_WriteEvent);
m_WriteEvent.WaitOne();
}private void SendLoginEmail(object state)
{
m_Mutex.WaitOne();string server = "mail.server.com";
string to = "123@123.com";
string from = "123@123.com";
string subject = "Using the SMTP client.";
string body = @"Message Body";MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient(server);
client.Timeout = 100;// change this to set username and password if required by SMTP server
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);m_Mutex.ReleaseMutex();
((AutoResetEvent)state).Set();
} -
sorry but may i know what program u are using to do this? Because im actually doing a asp.net page and i'm quite sure that some of the keywords used is not the same though. lost in codings, frossie
asp.net check out the threading namespace for the Mutex and AutoResetEvent and System.Web.Mail for the Emailing side of things hope that helps, g00fy if you get really stuck, email me your code and i'll take a look, or post your login routine and i'll modify it for you