Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Email Trigger

Email Trigger

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nettutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    frossie
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • F frossie

      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

      G Offline
      G Offline
      g00fyman
      wrote on last edited by
      #2

      not sure i understand requirements, but can you have your login routine send an email? or have i completely missed the point? g00fy

      F 1 Reply Last reply
      0
      • G g00fyman

        not sure i understand requirements, but can you have your login routine send an email? or have i completely missed the point? g00fy

        F Offline
        F Offline
        frossie
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • F 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

          G Offline
          G Offline
          g00fyman
          wrote on last edited by
          #4

          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);
          
          F 1 Reply Last reply
          0
          • G g00fyman

            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);
            
            F Offline
            F Offline
            frossie
            wrote on last edited by
            #5

            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

            G 1 Reply Last reply
            0
            • F frossie

              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

              G Offline
              G Offline
              g00fyman
              wrote on last edited by
              #6

              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();
              }

              F 1 Reply Last reply
              0
              • G g00fyman

                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();
                }

                F Offline
                F Offline
                frossie
                wrote on last edited by
                #7

                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

                G 1 Reply Last reply
                0
                • F frossie

                  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

                  G Offline
                  G Offline
                  g00fyman
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups